0

I have a CXF RESTful service which is working just fine. Problem is when I try to inject my DAO using an annotation:

@Resource
private MyDAO myDAO;

It's not getting injected. My JAX-RS service is Spring configured like so:

<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:cxf="http://cxf.apache.org/core"
      xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.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://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">


  <import resource="classpath:META-INF/cxf/cxf.xml"/>
  <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

  <jaxrs:server id="message" serviceClass="com.foo.MessageResourceImpl" address="/">
    <jaxrs:features>
         <cxf:logging/>
    </jaxrs:features>
  </jaxrs:server>
</beans>

The DAO is getting initialized by Spring and I have verified the bean works in any other POJO, just not the CXF service. Furthermore, I don't see any errors in the logs

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Andrew
  • 716
  • 1
  • 8
  • 19

1 Answers1

0

The solution is to serviceBeans:

<jaxrs:serviceBeans>
    <bean class="com.foo.MessageResourceImpl"/>
</jaxrs:serviceBeans>

When using @serviceClass, CXF instantiates the class, not Spring.

Andrew
  • 716
  • 1
  • 8
  • 19
  • Is it possible to autodiscover that beans as I ask in this related question http://stackoverflow.com/questions/13520821/autodiscover-jax-rs-resources-with-cxf-in-a-spring-application ? – Guido Nov 25 '12 at 13:33