title: Spring bean not injected into CXF web service, Why?
body: <p>I am writing a RESTful service (using CXF on JBoss) in which I have inject another class using Spring (Autowired). But the class is not getting injected and is null.</p>
  
  <p><strong>Web Service Interface and Class (Where injection needs to happen)</strong></p>
  
  <pre><code>package com.company.project.web;
  
  @Path("/myws")
  public interface IMyWebService {    
     @POST
     @Path("/doSomething")    
     @Consumes("application/json")
     @Produces("application/json")
      MyResponse doSomething(MyRequest myRequest)
  }
  
  @Service("myWebService")
  public class MyWebService implements IMyWebService {    
      @Autowired
      private IMyCore myCore;
  
      public MyResponse doSomething(MyRequest myRequest) {
        ....
      }
  }
  </code></pre>
  
  <p><strong>That which has to be injected</strong></p>
  
  <pre><code>package com.company.project.biz;
  
  public interface IMyCore {
     MyResponse doSomething(MyRequest myRequest);
  }
  
  @Component("myCore")
  public class MyCore implements IMyCore {
      public MyResponse doSomething(MyRequest myRequest) {
              .....
      }
  }
  </code></pre>
  
  <p>Beans.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:jaxws="http://cxf.apache.org/jaxws"
      xmlns:jaxrs="http://cxf.apache.org/jaxrs"
      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://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd    
      http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;import resource="classpath:META-INF/cxf/cxf.xml" /&gt;
      &lt;import resource="classpath:META-INF/cxf/cxf-servlet.xml" /&gt;
      &lt;import resource="classpath:META-INF/cxf/cxf-extension-http.xml" /&gt;
      &lt;import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /&gt;
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="com.company.project"/&gt;    
  
      &lt;jaxrs:server id="myWebService" address="/"&gt;
          &lt;jaxrs:serviceBeans&gt;
              &lt;bean class="com.company.project.web.MyWebService" /&gt;
          &lt;/jaxrs:serviceBeans&gt;
          &lt;jaxrs:extensionMappings&gt;
              &lt;entry key="json" value="application/json" /&gt;
          &lt;/jaxrs:extensionMappings&gt;
      &lt;/jaxrs:server&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>My service is active (<a href="http://localhost:8080/%7Bwarname%7D/myws/doSomething" rel="noreferrer">http://localhost:8080/{warname}/myws/doSomething</a>) but the MyCore instance is not being injected into MyWebService (in the myCore field). It is always null and my service does not work as expected, instead throws NullPointerException</p>
  
  <p>Tried all inputs gathered over google. No luck! Your help is highly appreciated.</p>
  
  <p>Regards</p>