首页 > 解决方案 > Log4jConfigurer 无法解析

问题描述

我正在从 spring 版本 4 迁移到 spring 版本 5。在 org.springframework.utils.Log4jConfigurer 中出现错误。

错误是:无法解析符号 Log4jConfigurer

还尝试将 apache Log4j 版本更改为 2,但错误仍然存​​在。Spring 5 中 Log4jConfigurer 的替代方案是什么?任何帮助。

我使用的是 Spring 4.XX 并使用以下设置来配置 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:mylog4j.properties</value>
        </list>
    </property>
</bean>

标签: springlog4j

解决方案


您不必定义 Log4JConfigurer。只需将 log4j.properties 添加到您的类路径即可配置 log4j。Spring 5 会找到它,您可以使用 Log4J。关于 Log4j 的版本,我在 Spring 5 项目中使用的是 1.2.17 版本,它运行良好。


推荐阅读