Spring+CXF Service类中无法注入Dao

在用Spring+CXF开发webservice的时候发现一个问题,CXF监听之后的实现类不能注入Dao,在网上查了点别人的资料,解决了问题
首先Spring的注入配置还是像一般的Spring一样注入

spring-config_ruleService.xml

<!-- 把产品信息的DAO的对象注入到service中 -->
   <bean id="RuleService" class="com.xxx.service.ruleWebservice.impl.RuleServiceImpl">  
   	<!-- 注入Dao实例 -->
	<property name="ruleServiceDao" ref="ruleServiceDao"></property>
     
   </bean>
<!-- 实例化Hibernate实现DAO -->
	<bean id="ruleServiceDao" class="com.xxx.dao.extend.impl.RuleServiceDaoImpl"  parent="daoTemplate" />


不过CXF的配置文件要有注意的地方
cxf/webservice.xml

<!-- 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" />

	<!-- 注册对外接口 implementor是实现类 address是web service地址 -->

	<jaxws:endpoint id="ruleService"
		implementorClass="com.xxx.service.ruleWebservice.RuleService"
		implementor="#RuleService" address="/ruleService" />


注意这个配置implementorClass就是配置这个service的interface,然后implementor就是去引用Spring容器中的RuleService这个bean,这样配置,就能在webservice的实现service中注入dao了。

猜你喜欢

转载自nealcai.iteye.com/blog/1956613