从 log4j 1.2 迁移到新的 log4j 2. 添加到 pom:
<!-- Add log4j version 2 with 1.2 API -->
<dependency>
<!-- <groupId>log4j</groupId> -->
<!-- <artifactId>log4j</artifactId> -->
<!-- <version>1.2.9</version> -->
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-beta6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.0-beta6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-beta6</version>
</dependency>
并尝试通过 Spring 上下文将其初始化为 log4j(在 log4j 1.2 上完美运行)。用于这样的配置:
<!-- Init log4j with appropriate config according to enviroment -->
<bean id="log4jConfigurer-bean" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer"/>
<property name="targetMethod" value="initLogging"/>
<property name="arguments">
<list>
<value>classpath:config/env/log4j-${env.variable}.xml</value>
</list>
</property>
</bean>
但是现在好像不行了?我做错了什么?可能是spring config应该修改?对 spring 使用这样的依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>