title: Accessing spring bean from logging appender class
body: <p>I have log4j DailyRollingFileAppender class in which setFile() method I need to check database value to decide which file to used for logging.</p>
  
  <pre><code>DailyRollingFileAppender class 
  
  public void setFileName()
  {
      isLoginEnabled = authenticationManager.checkLoginLogging();
  }
  </code></pre>
  
  <p>Here 'authenticationManager' is object of class used to make database call using spring dependency injection feature.</p>
  
  <pre><code>spring-beans.xml
  &lt;bean id="dailyRollingFileAppender" class="com.common.util.DailyRollingFileAppender"&gt;
   &lt;property name="authenticationManager"&gt;
       &lt;ref bean="authenticationManager"/&gt;
   &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="authenticationManager" class="com.security.impl.AuthenticationManagerImpl"&gt;
      &lt;property name="userService"&gt;
          &lt;ref bean="userService"/&gt;
  &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Now when I start my application log4j gets initiated first and since spring-beans is yet to invoked it throws NullPointerException in method setFileName(). 
  So is there a way I can make call to 'authenticationManager.checkLoginLogging();' from DailyFileAppender class so that when log4j loads it should able to get database value?</p>