title: NullPointerException with @Autowired in Spring
body: <p>I try to use Spring framework with @Autowired annotation to get a Service class.</p>
  
  <p>Here my class (this class is called by a <strong>WebSocketServlet</strong>) which need to use the Service (<strong>I get NullPointerException on call of it</strong>):</p>
  
  <pre><code>public class SignupWebSocketConnection extends MessageInbound {
  
      private static final Logger log = LoggerFactory.getLogger(SignupWebSocketConnection.class);
  
      @Autowired
      private UserService userService;
  
      @Override
      protected void onOpen(WsOutbound outbound) {
          log.info("Connection done");
      }
  
      @Override
      protected void onClose(int status) {
          log.info("Connection close");
      }
  
      @Override
      protected void onBinaryMessage(ByteBuffer byteBuffer) throws IOException {
          log.warn("Binary message are not supported");
          throw new UnsupportedOperationException("Binary message are not supported");
      }
  
      @Override
      protected void onTextMessage(CharBuffer charBuffer) throws IOException {
  
          User userTest = new User("log", "pass", "ema");
          userService.create(userTest);
  
      }
  }
  </code></pre>
  
  <p>Here my web.xml :</p>
  
  <pre><code>&lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/applicationContext*.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  </code></pre>
  
  <p>Here my ApplicationContext.xml :</p>
  
  <pre><code>&lt;bean id="userService" class="service.UserService"&gt;
  </code></pre>
  
  <p><strong>If I try to use the Service in the test package (I using maven) with explicit call of the ApplicationContext-test.xml, it's working fine... The ApplicationContext.xml and ApplicationContext-test.xml are same (just param to database changes)</strong></p>
  
  <p>Thank's a lot to all of you :D</p>
  
  <p>EDIT : </p>
  
  <p>I deplace my applicationContext.xml in ressources folder and create a class to test :</p>
  
  <pre><code>   public static void main(String[] args) {
          ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
          UserService userService = (UserService) ctx.getBean("userService");
          User user = new User("log","pas","emai");
          userService.create(user);
      }
  </code></pre>
  
  <p><strong>I get NullPointerException also when calling userService.create() ...</strong>.</p>