title: Spring autowired bean causes null pointer
body: <p>I have a logger class that makes use of a service. Each time a new logger is created, I expect to have access to the singleton scoped logging service.</p>
  
  <p>I autowire the logging service into the logger however, a null pointer exception is returned. I have tried a few solutions:</p>
  
  <ol>
  <li>manually defining the bean in the application context, </li>
  <li>Trying to get the logger to be spring managed but that just resulted in more issues.</li>
  </ol>
  
  <p>I am trying to get this to work in my junit tests, and I do specify the context file to make use of a different application context. However even if kept identical it does not resolve the issue.</p>
  
  <p>Please find code below:</p>
  
  <p>The following is an excerpt from the application context.</p>
  
  <pre><code>&lt;context:component-scan base-package="com.platform"/&gt;
  &lt;bean id="asyncLoggingService" class="com.platform.services.AsyncLoggingServiceImplementation" scope="prototype"/&gt;
  </code></pre>
  
  <p>The following is the Logger class.</p>
  
  <pre><code>package com.platform.utils;
  
  
  import com.platform.services.AsyncLoggingService;
  import org.joda.time.DateTime;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  
  public class OurLogger
  {
  
    private static Logger logger;
  
    @Autowired
    private AsyncLoggingervice asyncLoggingService;
  
    public OurLogger(Class Clazz)
    {
      logger = LoggerFactory.getLogger(Clazz);
    }
  
  
    public void trace(TraceableObject object, String message)
    { 
      //Do nothing yet
    }
  </code></pre>
  
  <p>}</p>
  
  <p>I then make use of the Logger in another service in order to log whats going on. (The reason I am writing another logger is to make use of an RabbitMQ server) In the service I instantiate a new instance of the Logger and then use it accordingly.</p>
  
  <pre><code>@Service
  public class AsyncAccountServiceImplementation implements AsyncAccountService
  {
    private static final String GATEWAY_IP_BLOCK = "1";
  
    private static OurLogger logger = new      OurLogger(AsyncAccountServiceImplementation.class);
  
  ...
  }
  </code></pre>
  
  <p>The null pointer occurs in the <code>OurLogger</code> when I try to call any method on the <code>asyncLoggingService</code>.</p>
  
  <p>I then am trying to test the <code>AsyncAccountService</code> using JUnit. I make sure I add the different application context but it still seems to result in the null pointer exception.</p>
  
  <p>If you need further information please let me know. I have seen ways to fix this but they don't seem to work so perhaps I have made a mistake somewhere or I am not understanding this all quite correctly.</p>