CXF中使用Autowired注解无法注入bean的有关问题

来源:互联网 发布:Linux cookie设置 编辑:程序博客网 时间:2024/06/06 07:52

在WebService的implementor中用@Autowired注入用@Component,@Resposrity,@Service注解标记的bean,都失败了,得到的都是null。google一番后找到了结果,只要改变一下配置文件写法即可。

package aitajian.ws;import javax.annotation.Resource;import javax.jws.WebService;import aitajian.entity.Order;import aitajian.mapper.ReimburseMapper;@WebServicepublic class OrderWsIpml implements OrderWs {@Autowiredprivat@Autowirede ReimburseMapper rm;public OrderWsIpml() {System.out.println("OrderWsIpml()");}@Overridepublic Order getOrderById(int id) {System.out.println("server getOrderById() "+id);System.out.println(rm+"-------------");System.out.println(rm.getReimburse(3));return new Order(id,"飞机",1000000);}}

原配置:

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jaxws="http://cxf.apache.org/jaxws"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"><!-- 引入cxf的一些核心配置 --><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" /><jaxws:endpointid="orderWS"implementor="aitajian.ws.OrderWsIpml"  address="/orderws" /></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"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"><!-- 引入cxf的一些核心配置 --><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" /><bean name="orderWsIpml" class="aitajian.ws.OrderWsIpml"/> <jaxws:endpointid="orderWS"implementor="#orderWsIpml"  address="/orderws" /></beans>

主要区别是原本jaxws中的implementor属性是直接写实现类的fullClass,现在改成ref bean的方式。

也可以使用@Component注解标记实现类为一个bean,然后implementor属性用# + bean的名字来reference这个bean即可。这和使用配置文件的方式来配置bean,写法是大同小异的。




2 0
原创粉丝点击