【问题标题】:Annotated beans not getting injected for JAX-RS CXF service没有为 JAX-RS CXF 服务注入带注释的 bean
【发布时间】:2011-11-21 23:13:43
【问题描述】:

我有一个运行良好的 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 正在由 Spring 初始化,并且我已经验证了 bean 在任何其他 POJO 中的工作,但不是 CXF 服务。此外,我在日志中看不到任何错误

【问题讨论】:

    标签: cxf jax-rs


    【解决方案1】:

    解决办法是serviceBeans:

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

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

    【讨论】:

    猜你喜欢
    • 2013-03-05
    • 2011-03-02
    • 1970-01-01
    • 2012-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 1970-01-01
    相关资源
    最近更新 更多