spring中log4j配置文件不放在classpath的根目录

时间:2022-04-29 23:41:40

前言

  • spring默认加载的是classpath根目录下面的log4j.properties,如果要放在其他目录,则需要按如下配置

  • 在web.xml中配置

配置

<!-- 指定log4j配置文件log4j.properties的位置(如果是在classpath根路径下,可以不配置) -->  
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:config/log4j.properties</param-value>
</context-param>

<!-- 配置spring中对于log4j的listener,注意该Listener要在spring的listener之前 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>