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兩點解決的
