相关疑难解决方法(0)

从日志记录appender类访问spring bean

我有log4j DailyRollingFileAppender类,其中setFile()方法我需要检查数据库值以决定用于记录的文件.

DailyRollingFileAppender class 

public void setFileName()
{
    isLoginEnabled = authenticationManager.checkLoginLogging();
}
Run Code Online (Sandbox Code Playgroud)

这里'authenticationManager'是类的对象,用于使用spring依赖注入功能进行数据库调用.

spring-beans.xml
<bean id="dailyRollingFileAppender" class="com.common.util.DailyRollingFileAppender">
 <property name="authenticationManager">
     <ref bean="authenticationManager"/>
 </property>
</bean>

<bean id="authenticationManager" class="com.security.impl.AuthenticationManagerImpl">
    <property name="userService">
        <ref bean="userService"/>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)

现在当我启动我的应用程序时,log4j首先被启动,并且因为spring-beans尚未被调用,所以它会在方法setFileName()中抛出NullPointerException.那么我有没有办法调用'authenticationManager.checkLoginLogging();' 来自DailyFileAppender类,以便在log4j加载时它应该能够获取数据库值吗?

spring log4j

4
推荐指数
1
解决办法
2381
查看次数

标签 统计

log4j ×1

spring ×1