隨筆-57  評論-117  文章-1  trackbacks-0

          在CXF2版本中,整合Spring3發(fā)布CXF WebService就更加簡單了。因為Spring 3提供了annotation注解,而CXF2發(fā)布WebService已經(jīng)不像之前版本的配置那樣(參考老版本發(fā)布WebService系列文章:http://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html),現(xiàn)在發(fā)布一個WebService可以直接從Spring的IoC容器中拿到一個對象,發(fā)布成WebService服務。當然發(fā)布WebService的配置有了些小小的變動,具體請往下看。

           

          在老版本中發(fā)布一個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的名稱就是訪問的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接口的實現(xiàn), 這種方法應該不能從Ioc中引用對象 -->
          <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容器中的對象為一個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的名稱就是訪問的WebService的name;#userServiceBean是直接引用Ioc容器中的Bean對象 -->
          <jaxws:server id="userService" serviceBean="#userServiceBean" address="/Users">
              <jaxws:inInterceptors>
                  <ref bean="inMessageInterceptor"/>
              </jaxws:inInterceptors>
              <jaxws:outInterceptors>
                  <ref bean="outLoggingInterceptor"/>
              </jaxws:outInterceptors>
          </jaxws:server>
          <!-- 或者這種方式,在老版本中這個是不能引用Ioc容器中的對象,但在2.x中可以直接用#id或#name的方式發(fā)布服務 -->
          <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



          作者:hoojo
          出處:
          blog:http://blog.csdn.net/IBM_hoojo
                   http://hoojo.cnblogs.com
          本文版權(quán)歸作者和博客園共有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權(quán)利。


          版權(quán)所有,轉(zhuǎn)載請注明出處 本文出自:
          分享道版權(quán)所有,歡迎轉(zhuǎn)載,轉(zhuǎn)載請注明出處,謝謝
          posted on 2012-07-13 17:47 hoojo 閱讀(3948) 評論(0)  編輯  收藏 所屬分類: FrameWork IntegrationJavaEESpringWebService
          主站蜘蛛池模板: 黄浦区| 德庆县| 封丘县| 科尔| 东乌| 通城县| 房产| 延津县| 清水县| 绩溪县| 新乡县| 丘北县| 班戈县| 九江县| 宜昌市| 广元市| 慈溪市| 滨州市| 东阿县| 诏安县| 双城市| 宁河县| 沧源| 沙坪坝区| 增城市| 黄冈市| 乐亭县| 云南省| 枞阳县| 陇川县| 许昌县| 合阳县| 延津县| 札达县| 赣榆县| 个旧市| 司法| 安图县| 高邮市| 平湖市| 乐昌市|