在CXF2版本中,整合Spring3發(fā)布CXF WebService就更加簡(jiǎn)單了。因?yàn)镾pring 3提供了annotation注解,而CXF2發(fā)布WebService已經(jīng)不像之前版本的配置那樣(參考老版本發(fā)布WebService系列文章:http://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html),現(xiàn)在發(fā)布一個(gè)WebService可以直接從Spring的IoC容器中拿到一個(gè)對(duì)象,發(fā)布成WebService服務(wù)。當(dāng)然發(fā)布WebService的配置有了些小小的變動(dòng),具體請(qǐng)往下看。
在老版本中發(fā)布一個(gè)WebService,配置applicationContext-server.xml文件中添加如下配置如下:
jaxws:server的發(fā)布方式
<bean id="userServiceBean" class="com.hoo.service.ComplexUserService"/>
<bean id="inMessageInterceptor" class="com.hoo.interceptor.MessageInterceptor">
<constructor-arg value="receive"/>
</bean>
<bean id="outLoggingInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<!-- 注意下面的address,這里的address的名稱就是訪問(wèn)的WebService的name -->
<jaxws:server id="userService" serviceClass="com.hoo.service.IComplexUserService" address="/Users">
<jaxws:serviceBean>
<!-- 要暴露的 bean 的引用 -->
<ref bean="userServiceBean"/>
</jaxws:serviceBean>
<jaxws:inInterceptors>
<ref bean="inMessageInterceptor"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="outLoggingInterceptor"/>
</jaxws:outInterceptors>
</jaxws:server>
jaxws:endpoint的發(fā)布方式
<!-- com.hoo.service.ComplexUserService是com.hoo.service.IComplexUserService接口的實(shí)現(xiàn), 這種方法應(yīng)該不能從Ioc中引用對(duì)象 -->
<jaxws:endpoint id="userService2" implementor="com.hoo.service.ComplexUserService" address="/Users">
<jaxws:inInterceptors>
<ref bean="inMessageInterceptor"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="outLoggingInterceptor"/>
</jaxws:outInterceptors>
</jaxws:endpoint>
而在2.x新版本中,發(fā)布Ioc容器中的對(duì)象為一個(gè)WebService的方法
<bean id="userServiceBean" class="com.hoo.service.ComplexUserService"/>
<bean id="inMessageInterceptor" class="com.hoo.interceptor.MessageInterceptor">
<constructor-arg value="receive"/>
</bean>
<bean id="outLoggingInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<!-- 注意下面的address,這里的address的名稱就是訪問(wèn)的WebService的name;#userServiceBean是直接引用Ioc容器中的Bean對(duì)象 -->
<jaxws:server id="userService" serviceBean="#userServiceBean" address="/Users">
<jaxws:inInterceptors>
<ref bean="inMessageInterceptor"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="outLoggingInterceptor"/>
</jaxws:outInterceptors>
</jaxws:server>
<!-- 或者這種方式,在老版本中這個(gè)是不能引用Ioc容器中的對(duì)象,但在2.x中可以直接用#id或#name的方式發(fā)布服務(wù) -->
<jaxws:endpoint id="userService2" implementor="#userServiceBean" address="/Users">
<jaxws:inInterceptors>
<ref bean="inMessageInterceptor"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="outLoggingInterceptor"/>
</jaxws:outInterceptors>
</jaxws:endpoint>
CXF發(fā)布WebService官方參考:http://cxf.apache.org/docs/writing-a-service-with-spring.html
版權(quán)所有,轉(zhuǎn)載請(qǐng)注明出處 本文出自:
版權(quán)所有,歡迎轉(zhuǎn)載,轉(zhuǎn)載請(qǐng)注明出處,謝謝