我使用的是Spring4.X.X,并使用下面的设置配置Log4j。现在我将其升级到Spring5.0.2,其中Log4jConfigurer
类已被删除。我如何在Spring 5.0.2中做到这一点?
<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:log4j.properties</value>
</list>
</property>
</bean>
发布于 2018-01-05 17:17:58
Log4JConfigurer
是非默认Log4j初始化所必需的,例如,如果使用自定义配置文件名/位置,但您的配置文件位于默认位置:classpath:log4j.properties
,因此您只需删除Log4jConfigurer
声明,Spring就会自动发现您的log4j.properties
。
这里有一个可能的警告;Spring5使用Log4j v2 (遵循Apache1.x的EOL声明),所以只要你使用的是log4j v2,Spring5就会自动检测它和你的log4j.properties
文件,而不需要声明一个Log4JConfigurer
。如果您当前没有使用Log4j v2,那么我认为您需要升级,因为Spring5不支持使用Log4j v1.x。
https://stackoverflow.com/questions/48107537
复制相似问题