title: @Autowire null inside a servlet
body: <p>the service inside this servlet is null if I use @Autowired, it works fine using context.getBean(); furthermore the mapping with /floorOperationWS/ is not done, I have to define the mapping inside web.xml.</p>
  
  <pre><code>package com.confloorapp.services.endpoint;
  
  import java.io.IOException;
  import java.util.Date;
  import java.util.Enumeration;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.web.context.support.WebApplicationContextUtils;
  
  
  
  @WebServlet(value = "/floorOperationWS/")
  public class UpdateFloorEventServlet extends HttpServlet {
  
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
  
  
              FloorService floorService = (DoorService)context.getBean("floorService");
  
  }
  
  
  
  }
  </code></pre>
  
  <p>Here applicationContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:sws="http://www.springframework.org/schema/web-services"
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              http://www.springframework.org/schema/mvc 
              http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
              http://www.springframework.org/schema/web-services 
              http://www.springframework.org/schema/web-services/web-services-2.0.xsd"&gt;
  
      &lt;!-- Activates various annotations to be detected in bean classes --&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;!-- Scans the classpath for annotated components that will be auto-registered 
          as Spring beans. For example @Controller and @Service. Make sure to set the 
          correct base-package --&gt;
      &lt;context:component-scan base-package="com.confloorapp" /&gt;
      &lt;context:annotation-config/&gt;
  
      &lt;!-- Configures the annotation-driven Spring MVC Controller programming 
          model. Note that, with Spring 3.0, this tag works in Servlet MVC only! --&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;!-- Load Hibernate related configuration --&gt;
      &lt;!-- Here you can also add spring security context, if exist --&gt;
      &lt;import resource="hibernate-context.xml" /&gt; 
      &lt;import resource="spring-security.xml" /&gt;
  
  &lt;/beans&gt;
  </code></pre>