注释的bean没有为JAX-RS CXF服务注入

时间:2011-01-04 00:19:42

标签: cxf jax-rs

我有一个CXF RESTful服务,工作得很好。问题是当我尝试使用注释注入我的DAO时:

@Resource
private MyDAO myDAO;

没有注射。我的JAX-RS服务是Spring配置的:

<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>

DAO正在初始化,我已经在任何其他POJO中验证了bean的工作原理,而不是CXF服务。此外,我没有在日志中看到任何错误

1 个答案:

答案 0 :(得分:0)

解决方案是serviceBeans:

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

使用@serviceClass时,CXF实例化类,而不是Spring。