title: Spring + Spring MVC dependency injection without using @Autowire
body: <p>I'm building an application using Spring and Spring MVC. For me using @Autowired is not an option (is a requirement).</p>
  <p>I have build a web.xml file like:</p>
  <pre><code>&lt;!-- Spring context --&gt;
  &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;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
  &lt;listener&gt;
  &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  
  &lt;!-- Spring MVC --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;namespace&lt;/param-name&gt;
          &lt;param-value&gt;mvc-dispatcher-context&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  <p>So I load Spring context and Spring MVC Servlet.</p>
  <p>My mvc-dispatcher-context.xml file looks like:</p>
  <pre><code>&lt;beans ...&gt;
  
      &lt;mvc:annotation-driven /&gt;
  
      &lt;context:component-scan base-package=&quot;com.pacage.controller&quot;/&gt;
  
      &lt;mvc:resources mapping=&quot;/resources/**&quot; location=&quot;/WEB-INF/static/&quot; /&gt;
  
      &lt;bean
      class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&gt;
      &lt;property name=&quot;prefix&quot;&gt;
          &lt;value&gt;/WEB-INF/pages/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name=&quot;suffix&quot;&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  <p>So I can use @Controller annotation in my controllers...</p>
  <p>And on my applicationContext.xml I have my Spring beans defined, such as my Services in this case &quot;OneService.java&quot;</p>
  <p>I have One controller as:</p>
  <pre><code>@Controller
  @RequestMapping(&quot;/main&quot;)
  public class MainController {
  
      private OneService oneService;
      //getters and setters
      ...
  }
  </code></pre>
  <p>Where I want to inject OneService which is defined in applicationContext.xml file.
  I've tried several ways but I can't get it working, always getting an NullPointerException when using my service inside the controller.</p>
  <p>Is there any way to use beans defined in applicationContext.xml inside this mvc servlet?</p>
  <p>[UPDATE]</p>
  <p>If I define all my applicatonContext inside my servlet I can't get it working. Is there any way to make servlet context a child of application context just to be able to use application context beans?</p>