问题描述
i使用了Spring 4.x.x,并使用以下设置来配置Log4J.现在正在将其升级到已删除Log4jConfigurer类的弹簧5.0.2.我该如何在春季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.
这里有一个可能的警告;弹簧5使用log4j v2(以下apache的eol声明为log4j 1.x),因此,只要您使用log4j v2,spring 5就会自动检测到它,而您的log4j.properties文件无需声明Log4JConfigurer.如果您当前不使用Log4J V2,那么我认为您需要升级,因为Spring 5不支持Log4JV1.X.
的使用.问题描述
I was using Spring 4.X.X and used the below setup to configure Log4j. Now am upgrading it to Spring 5.0.2 where the Log4jConfigurer class has been removed. How can I do it in 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>
推荐答案
The Log4JConfigurer was required for non default Log4j initialisation e.g. if using a custom config file name/location but your config file is located in the default location: classpath:log4j.properties so you can simply remove the Log4jConfigurer declaration and Spring will auto discover your log4j.properties.
There is one possible caveat here; Spring 5 uses Log4j v2 (following Apache's EOL declaration for log4j 1.x) so as long as you are using Log4j v2 then Spring 5 will auto detect it and your log4j.properties file without any need to declare a Log4JConfigurer. If you are not currently using Log4j v2 then I think you'll need to upgrade since Spring 5 does not support the use of Log4j v1.x.