论坛首页 Java企业应用论坛

Spring+CXF Service类中无法注入Dao

浏览 2823 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2013-10-14  
在用Spring+CXF开发webservice的时候发现一个问题,CXF监听之后的实现类不能注入Dao,在网上查了点别人的资料,解决了问题
首先Spring的注入配置还是像一般的Spring一样注入

spring-config_ruleService.xml

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

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

<pre name="code" class="xml">
&lt;!-- cxf的配置文件 --&gt;
&lt;import resource="classpath:META-INF/cxf/cxf.xml" /&gt;
&lt;import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /&gt;
&lt;import resource="classpath:META-INF/cxf/cxf-servlet.xml" /&gt;

&lt;!-- 注册对外接口 implementor是实现类 address是web service地址 --&gt;

&lt;jaxws:endpoint id="ruleService"
implementorClass="com.xxx.service.ruleWebservice.RuleService"
implementor="#RuleService" address="/ruleService" /&gt;

</pre>

注意这个配置implementorClass就是配置这个service的interface,然后implementor就是去引用Spring容器中的RuleService这个bean,这样配置,就能在webservice的实现service中注入dao了。
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics