转自:
http://www.myexception.cn/software-architecture-design/882646.html
CXF中使用Autowired注解无法注入bean的问题
之前学习了CXF,通过官方文档,学下来没什么大问题。今天用到实际项目中,在WebService的implementor中用@Autowired注入用@Component,@Resposrity,@Service注解标记的bean,都失败了,得到的都是null。google一番后找到了结果,只要改变一下配置文件写法即可。
implementor:
@WebService(endpointInterface = "demo.hw.server.HelloWorld", serviceName = "HelloWorld") @Component(value="helloWorldImpl") public class HelloWorldImpl implements HelloWorld { @Autowired private TestBean tBean; Map<Integer, User> users = new LinkedHashMap<Integer, User>(); public String sayHi(String text) { System.out.println("sayHi called"); System.out.println(tBean); if (tBean == null) { return "Hello " + text; }else{ return "Hello " + tBean.getValue(); } } }
原配置:
<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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" 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://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <context:component-scan base-package="demo" /> <jaxws:endpoint id="helloWorld" implementor="demo.hw.server.HelloWorldImpl" address="/HelloWorld"> </jaxws:endpoint> </beans>
新配置:
<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:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" 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://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <context:component-scan base-package="demo" /> <jaxws:endpoint id="helloWorld" implementor="#helloWorldImpl" address="/HelloWorld"> </jaxws:endpoint> </beans>
主要区别是原本jaxws中的implementor属性是直接写实现类的fullClass,现在改成ref bean的方式,使用@Component注解标记实现类为一个bean,然后implementor属性用# + bean的名字来reference这个bean即可。如果你使用的配置文件的方式来配置bean,其写法也是大同小异的。
相关推荐
cxf实现webservice 常用注解总结,本文档包括cxf实现webservice是用到所有注解,请大家参考
NULL 博文链接:https://j4t.iteye.com/blog/1535592
webservice cxf spring整合返回list,bean,string,json,xml项目完整实例
cxf使用中编码问题,有关于gbk等的编码问题在cxf中的解决方法
Tomcat下通过CXF实现不用注解发布WebService ,Tomcat下通过CXF实现不用注解发布WebService
cxf常用注解doc。全面注解。高效学习。欢迎下载。
在构造过程中,SpringBusFactory会搜索META-INF/cxf(包含在 CXF 的jar中)下的所有bean配置文件。 * 根据这些配置文件构建一个ApplicationContext。开发者也可以提供自己的配置文件来定制Bus。
基于spring注解的cxf实现webservice
Web Service Cxf转换器的示例,包含源码和jar包。
CXF webservice 使用实例,CXF创建webservice以及调用示例;WEBSERVICE输入、输出拦截器设置;用户验证;文件上传等。附带所有使用到的JAR包。
NULL 博文链接:https://zhaoshijie.iteye.com/blog/1714359
CXF框架简单介绍、CXF框架工具使用、CXF框架工具报错解决
为了整合Android后台而开发的使用Webservice的服务器端,导入MySQL数据库文件运行test中的类可以使用,在Android端如何使用请看下篇Android端的项目
这是我在使用cxf+spring进行开发中的一点总结,如何搭建开发环境、如何配置dao使用,如何解决乱码问题等的经验分享
是一个比较详细的cxf使用项目,里面有矿建搭建,也有cxf的使用,内容比较详细和丰富
CXF使用EndpointImpl发布WebService加入拦截器
3.抛弃cxf默认的log方式,使用log4j的方式,方便以后整合到其他app中而不改变之前系统log的方式。 答谢: 关于cxf的深入研究,我发现国人翻译的东西很少,我想尽自己的微薄之力能给大家带些有用的东西,如果有什么...
CXF中使用Simple FrontEnd Project方式发布并获取webservice服务
赠送jar包:cxf-core-3.0.1.jar; 赠送原API文档:cxf-core-3.0.1-javadoc.jar; 赠送源代码:cxf-core-3.0.1-sources.jar;...人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。
Apache CXF是一个开源的Service框架,它实现了JCP与Web Service中一些重要标准。CXF简化了构造,集成,面向服务架构(SOA)业务组件与技术的灵活复用。在CXF中,Service使用WSDL标准定义并能够使用各种不同的消息格式...