【问题标题】:Log4j2 JSP Taglib not working in Spring-boot Embedded Servlet ContainersLog4j2 JSP Taglib 在 Spring-boot Embedded Servlet 容器中不起作用
【发布时间】:2020-09-11 06:14:40
【问题描述】:

我有一个使用 spring-boot-starter-web 工件创建的 Spring Boot Web 应用程序。我正在使用 Spring Boot Embedded Servlet Containers 功能来使用 Tomcat 嵌入式服务器。我能够在 Tomcat 嵌入式模式下运行我的应用程序。我还可以创建我的应用程序的 WAR 文件并将其部署到 Tomcat 的正常安装中。

我有一个使用log4j2's JSP taglib 标签的JSP 页面。在 Tomcat 的正常安装中,来自该 JSP 页面的日志记录按预期工作。但是当在 Tomcat 嵌入式服务器上 bootRun 我得到以下错误

SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [The absolute uri: [http://logging.apache.org/log4j/tld/log] cannot be resolved in either web.xml or the jar files deployed with this application] with root cause
org.apache.jasper.JasperException: The absolute uri: [http://logging.apache.org/log4j/tld/log] cannot be resolved in either web.xml or the jar files deployed with this application

这个问题能解决吗?

【问题讨论】:

标签: spring-boot log4j2


【解决方案1】:

出现问题是因为 Spring Boot 默认跳过 log4j-*.jar。我已经打开 an issue 来解决这个问题。

您可以通过明确启用扫描log4j-taglib jar 来解决此问题。为此,您需要添加一个 TomcatContextCustomizer 来更改 jar 扫描器的配置:

@Bean
TomcatContextCustomizer log4jTldScanningCustomizer() {
    return (context) -> 
        ((StandardJarScanFilter)context.getJarScanner().getJarScanFilter()).setTldScan("log4j-taglib*.jar");
}

【讨论】:

    猜你喜欢
    • 2018-05-12
    • 2018-03-15
    • 2018-08-27
    • 2011-12-25
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    相关资源
    最近更新 更多