1. 首先logj4的:org.springframework.web.util.Log4jConfigListener(web.xml)配置出自spring-web的3.2.3版本。不能高过这个版本的spring-web。高的话在配置web.xml中就会出错!
see in spring github
https://github.com/spring-projects/spring-framework/wiki/What%27s-New-in-Spring-Framework-5.x
- Spring Framework 5.0 comes with its own Commons Logging bridge out of the box:
spring-jcl
instead of standard Commons Logging; still excludable/overridable.- Autodetecting Log4j 2.x, SLF4J, JUL (java.util.logging) without any extra bridges.
2. 添加maven配置
<!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
3. web.xml中配置
这里注意两个路径地址方式:
一种是放在java下被声明为resource资源的文件夹下:用classpath:来表示那个资源文件的根目录
一种是放在WEB-INF就这样写:<param-value>/WEB-INF/applicationContext.xml</param-value>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
4. 添加logj4的properties配置文件
被声明为resource资源的文件夹下创建:log4j.properties的一个配置文档
5. 配置详细
6. 调用