未为 JAX-RS CXF 服务注入带注释的 bean
我有一个 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 服务中无效。此外,我在日志中没有看到任何错误
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是serviceBeans:
当使用@serviceClass时,CXF实例化该类,而不是Spring。
The solution is to serviceBeans:
When using @serviceClass, CXF instantiates the class, not Spring.