title: @Autowired not working in Spring restful web service
body: <p>I am developing application using Struts2 + Spring4 + Hibernate4 with RESTful web service. I have configured Hibernate in Spring bean file. For RESTful web service I have excluded URL in <code>struts.xml</code> using</p>
  <pre><code>&lt;constant name=&quot;struts.action.excludePattern&quot; value=&quot;/service/.*&quot;/&gt; 
  </code></pre>
  <p>If I access <code>sessionFactory</code> object in any action class it works fine. But if I access it in my web service it gives <code>NullPointerException</code>.</p>
  <p>After searching on Google I found that if we bypass URL from Struts it does not allow to initialize object using <code>@Autowired</code> annotation.</p>
  <p>How to sort out this thing? I have searched on Google but nothing useful found.</p>
  <p><strong>This is my service:</strong></p>
  <pre><code>@Path(&quot;service/account-management&quot;)
  public class AccountServiceImpl implements AccountService {
      
      @Autowired
      private SessionFactory sessionFactory;
       
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
      @Override
      @POST
      @PermitAll
      @Path(&quot;/accounts&quot;)
      public Response getAllAccounts() {
          System.out.println(sessionFactory);
           Session session = this.sessionFactory.getCurrentSession();
           List&lt;VbarAccount&gt; personList = session.createQuery(&quot;from TEST&quot;).list();
           System.out.println(personList);
           session.close();
           return Response.status(200).build();
      }
  
  }
  </code></pre>
  <p><strong>This is my bean mapping:</strong></p>
  <pre><code>&lt;bean id=&quot;accountService&quot; class=&quot;com.xxx.yyy.services.impl.AccountServiceImpl&quot;&gt;
      &lt;property name=&quot;sessionFactory&quot; ref=&quot;hibernate4AnnotatedSessionFactory&quot; /&gt;
  &lt;/bean&gt;
  </code></pre>