我使用的是 Spring 4.X.X 并使用以下设置来配置 Log4j。现在正在将其升级到 Spring 5.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>
最佳答案
非默认 Log4j 初始化需要 Log4JConfigurer
,例如如果使用自定义配置文件名/位置,但您的配置文件位于默认位置:classpath:log4j.properties
因此您可以简单地删除 Log4jConfigurer
声明,Spring 将自动发现您的 log4j.properties
。
这里有一个可能的警告; Spring 5 使用 Log4j v2(遵循 Apache 对 log4j 1.x 的 EOL 声明),因此只要您使用 Log4j v2,Spring 5 就会自动检测它和您的 log4j.properties
文件,无需声明一个 Log4JConfigurer
。如果您当前没有使用 Log4j v2,那么我认为您需要升级,因为 Spring 5 不支持使用 Log4j v1.x。
关于java - Spring 5.0.2 中的 Log4jConfigurer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48107537/