title: Spring @Autowired property is null
body: <p>I apologize if this question has already been asked or answered somewhere. I have a sample code, which is not working as intended. Spring annotation <code>@Autowired</code> is not working. Whereas in the same setup I have <code>@Inject</code> working with Weld 1.1.0 and Tomcat 6.</p>
  
  <p><strong>WorkTester.java</strong></p>
  
  <pre><code>  //1. Do I need to mark some class as component to wire a property in that class? Intellij 
    //always warns if I don't.
    @Component
      public class WorkTester {
  
          @Autowired
          @Qualifier("work")
          private Work work;
          //2. There is a bean in MVC context with name work. Why doesn't it work?
  
          public void testWork() {
              System.out.println("Work : " + work);
          }
  
          public Work getWork() {
              return work;
          }
  
          //2. If there is a bean called 'work' in any of the contexts, do I need setters?
          public void setWork(Work work) {
              this.work = work;
          }
      }
  </code></pre>
  
  <p><strong>WorkImpl.java</strong></p>
  
  <pre><code>public class WorkImpl implements Work {
  
      @Override
      public void doWork(String task) {
          System.out.println("Yahoo! " + task);
      }
  }
  </code></pre>
  
  <p>I have <code>applicationContext.xml</code>, which is empty. My <code>dispatcher-servet.xml</code> is</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"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;context:component-scan base-package="com.brs.in"/&gt;
  
      &lt;bean id="work" class="com.brs.in.WorkImpl"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>My <strong>web.xml</strong>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
      &lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.jboss.weld.environment.servlet.Listener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;test&lt;/servlet-name&gt;
          &lt;servlet-class&gt;com.brs.in.HelloWorldServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;test&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/test&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;resource-env-ref&gt;
          &lt;resource-env-ref-name&gt;BeanManager&lt;/resource-env-ref-name&gt;
          &lt;resource-env-ref-type&gt;javax.enterprise.inject.spi.BeanManager&lt;/resource-env-ref-type&gt;
      &lt;/resource-env-ref&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>As mentioned in the comments(Questions 1, 2, 3) in the first snippet of code, can anyone answer why autowiring is not working?</p>
  
  <p><strong>Entry Point:</strong></p>
  
  <p>This is the sample servlet where I am calling the method causing <code>NullPointerException</code>:</p>
  
  <pre><code>    @Inject
      private Work worker;
  
      @Override
      protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException {
  
          System.out.println("Worker has been injected " + ((worker != null)));
  
          worker.doWork(1, 2);//No Problem
  
          new WorkTester().testWork();//Causing trouble
  
      } 
  </code></pre>