web.xml配置如下
<!--log4j2--> <context-param> <param-name>log4jConfiguration</param-name> <param-value>classpath:log4j/log4j2.xml</param-value> </context-param> <listener> <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class> </listener>
程序启动报错
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
解决方法,对照如下逐一核查
- Tomcat 7.0.43以前的版本,需要从catalina.properties的配置项【jarsToSkip】中屏蔽掉“log4j*.jar”这一选项。
- context-param中关于配置文件的路径信息配置是【log4jConfiguration】而不是log4jConfigLocation。
- web.xml中的Servlet的版本声明应该是3.0,具体如下:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
本人是修改了2,3两点解决的