我有一个使用Spring的Log4jConfigurer类来初始化我的Log4J日志工厂的Web应用程序.基本上它使用不在类路径中的配置文件初始化Log4J.
这是配置:
<bean id="log4jInitializer" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean" depends-on="sbeHome">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>#{ MyAppHome + '/conf/log4j.xml'}</value>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
但是我在应用程序启动时收到此错误:
log4j:WARN No appenders could be found for logger
大量的Spring应用程序上下文初始化消息被打印到控制台.我认为这是因为Spring在有机会初始化我的记录器之前正在开始初始化我的应用程序.如果它很重要,我在Log4J上使用SLF4J.
有没有办法让我的Log4jConfigurer成为第一个初始化的bean?还是有其他方法来解决这个问题?