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

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

           

          在老版本中發布一個WebService,配置applicationContext-server.xml文件中添加如下配置如下:

          jaxws:server的發布方式

          <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的發布方式

          <!-- com.hoo.service.ComplexUserService是com.hoo.service.IComplexUserService接口的實現, 這種方法應該不能從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新版本中,發布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的方式發布服務 -->
          <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發布WebService官方參考:http://cxf.apache.org/docs/writing-a-service-with-spring.html



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


          版權所有,轉載請注明出處 本文出自:
          分享道版權所有,歡迎轉載,轉載請注明出處,謝謝
          posted on 2012-07-13 17:47 hoojo 閱讀(3938) 評論(0)  編輯  收藏 所屬分類: FrameWork IntegrationJavaEESpringWebService
          主站蜘蛛池模板: 黑龙江省| 义乌市| 渑池县| 唐海县| 小金县| 建宁县| 达日县| 新巴尔虎左旗| 克山县| 平和县| 洛阳市| 尖扎县| 嘉峪关市| 泰和县| 当涂县| 蒙城县| 抚远县| 陕西省| 九龙县| 闽侯县| 科技| 云阳县| 吉安市| 乌鲁木齐市| 黄浦区| 封开县| 抚顺市| 云阳县| 达尔| 旌德县| 成武县| 房山区| 太仆寺旗| 宁明县| 潼关县| 台湾省| 阿克陶县| 平乡县| 青田县| 沈阳市| 博湖县|