Spring 5.0.2中的Log4jConfigurer

编程入门 行业动态 更新时间:2024-10-28 12:23:57
本文介绍了Spring 5.0.2中的Log4jConfigurer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用的是Spring 4.X.X,并使用以下设置来配置Log4j.现在将其升级到已删除Log4jConfigurer类的Spring 5.0.2.在Spring 5.0.2中如何做?

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>

推荐答案

Log4JConfigurer是非默认Log4j初始化所必需的,例如如果使用自定义配置文件名/位置,但是您的配置文件位于默认位置:classpath:log4j.properties,那么您只需删除Log4jConfigurer声明,Spring就会自动发现您的log4j.properties.

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.

这里可能有一个警告: Spring 5使用Log4j v2(遵循Apache的log4j 1.x的EOL声明),因此只要您使用Log4j v2,Spring 5就会自动检测到它和您的log4j.properties文件,而无需声明Log4JConfigurer.如果您当前不使用Log4j v2,那么我认为您需要进行升级,因为Spring 5不支持使用Log4j v1.x.

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.

更多推荐

Spring 5.0.2中的Log4jConfigurer

本文发布于:2023-11-12 18:02:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582162.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Spring   Log4jConfigurer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!