Spring 5.0.2 中的 Log4jConfigurer

Log4jConfigurer in Spring 5.0.2

我正在使用 Spring 4.X.X 并使用以下设置来配置 Log4j。现在正在将其升级到 Spring 5.0.2,其中 Log4jConfigurer class 已被删除。我怎样才能在 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,例如如果使用自定义配置文件 name/location 但您的配置文件位于默认位置:classpath:log4j.properties 因此您只需删除 Log4jConfigurer 声明并且 Spring 将自动发现您的 log4j.properties.

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