春季:无法覆盖log4j配置

时间:2019-04-14 08:18:20

标签: java spring logging log4j

我试图覆盖配置,但spring仍然从jar中获取log4j配置文件。我的项目类路径是/ src。当我将自己的log4j.properties文件放在src文件夹中时,spring可以加载我的log4j属性文件,但是当我尝试从资源文件夹中加载log4j属性文件时,spring不会加载我的log4j文件。下面是我用来从另一个文件夹加载我的log4j属性文件的代码。

<context-param>
        <param-name>spring.profiles.active</param-name>
        <param-value>qa</param-value>
    </context-param>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:main/resources/log4j-dev.properties</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

有,spring没有加载我的log4j-dev.properties文件。我也尝试过使用@PropertySource,但面临相同的问题。

@Configuration
@PropertySource(value = {"/main/resources/application-qa.properties","/main/resources/log4j-dev.properties"})
@Profile("qa")
public class QaProfileConfig {


}

Jar文件中的log4j配置

<bean id="log4jInitialization"
     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:#{systemProperties['config.env'].toLowerCase()}/log4j.properties</value>
          </list>
       </property>
    </bean>

这是config.env = test,因此它总是从test文件夹加载属性文件。请帮忙,我如何通过自己的内部log4j覆盖jar log4j配置。

0 个答案:

没有答案
相关问题