web.xml配置log4j2路徑問題


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.

解決方法,對照如下逐一核查

  1. Tomcat 7.0.43以前的版本,需要從catalina.properties的配置項【jarsToSkip】中屏蔽掉“log4j*.jar”這一選項。
  2. context-param中關於配置文件的路徑信息配置是【log4jConfiguration】而不是log4jConfigLocation。
  3. 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兩點解決的

參考

一沙世界的博客
官網說明


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM