title: NullPointerException while using @Autowired in maven webapp
body: <p>I am trying to integrate Jersey with Spring using maven <code>webapp-archetype</code>. When I get the object form the ApplicationContext I see my code executing, but when I try to use <code>@Autowired</code> it throws me <code>NullPointerException</code>. Following are the code snippets:</p>
  
  <p>applicationContext.xml</p>
  
  <pre><code>&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-4.0.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-4.0.xsd"&gt;
  
  &lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.pack.resource" /&gt;
  &lt;bean id="person" class="com.pack.resource.Person"&gt;
      &lt;property name="name" value="SomeNamexxxx" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>Person.java</p>
  
  <pre><code>package com.pack.resource;
  
   public class Person {
  
  private String name;
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public Person() {
  
  }
  
   }
  </code></pre>
  
  <p>Hello.java</p>
  
  <pre><code>package com.pack.resource;
  
   import javax.ws.rs.GET;
   import javax.ws.rs.Path;
   import javax.ws.rs.Produces;
  
   import org.springframework.beans.factory.annotation.Autowired;
   import javax.ws.rs.core.MediaType;
   import org.springframework.stereotype.Component;
  
   @Component
   @Path("/hello")
   public class Hello {
  
   @Autowired
   Person person;
  
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String getName() {
  
      return person.getName();
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>But when I use <code>ApplicationContext.getBean("person").getName()</code> it gives me the actual value inside the bean property.
  Why is <code>@Autowired</code> annotation not working as it should. Kindly help me.
  TIA! </p>