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

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

@WebService
public class OrderWsIpml implements OrderWs {
	@Autowired
	privat@Autowirede ReimburseMapper rm;
	
	public OrderWsIpml() {
		System.out.println("OrderWsIpml()");
	}

	@Override
	public 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/beans
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://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:endpoint
	id="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/beans
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://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:endpoint
	id="orderWS"
	implementor="#orderWsIpml"  
	address="/orderws" />
	
</beans>

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

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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值