XFire+Spring發佈Web Service(二)

上接XFire+Spring發佈Web Service(一)

2.配置文件及發佈
下面就可以配置Spring和XFire,以及Web.xml等配置文件了。XFire發佈Web Service有兩種方式,一種是利用XFire的導出器,一種是利用在發佈接口和實現類的相應位置添加註釋,這種註釋的標準是由BEA提出來的——JSR181,兩者各有利弊,利用導出器無需對原有代碼進行修改;而利用第二種方法,不適用改造現有系統,似乎只適合新開發Web Services的項目。本文暫時只講第一種方法。
先看一下Web.xml文件的配置,重要代碼添加了註釋:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <context-param>

       <!-- Spring配置文件 -->

       <param-name>contextConfigLocation</param-name>

       <param-value>classpath:applicationContext.xml</param-value>

 

 

    </context-param>

 

   

    <listener>

       <listener-class>

           org.springframework.web.context.ContextLoaderListener

       </listener-class>

    </listener>

    <!-- 配合Spring容器中XFire一起工作的Servlet -->

    <servlet>

       <servlet-name>xfireServlet</servlet-name>

       <servlet-class>

           org.codehaus.xfire.spring.XFireSpringServlet

       </servlet-class>

    </servlet>

    <servlet-mapping>

       <servlet-name>xfireServlet</servlet-name>

       <url-pattern>/service/*</url-pattern><!-- 在這個URI下開放Web Service服務 -->

    </servlet-mapping>

</web-app>

接着我們來看一看Spring的配置文件,相關處有註釋:

<?xml version="1.0" encoding="UTF-8" ?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="

    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <!--引入XFire的預配置文件-->

    <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />

    <bean id="HelloServiceImpl" class="demo.HelloServiceImpl" />

 

    <!-- 使用導出器導出Web Service -->

    <bean id="HelloService"

        class="org.codehaus.xfire.spring.remoting.XFireExporter"><!-- XFire導出器 -->

        <!-- 引用XFire.xml中定義工作 -->

        <property name="serviceFactory" ref="xfire.serviceFactory" />

        <!-- 引用XFire.xml中定義的XFire實例 -->

        <property name="xfire" ref="xfire" />

        <!-- 業務服務Bean -->

        <property name="serviceBean" ref="HelloServiceImpl" />

        <!-- 業務服務Bean的窄接口類 -->

        <property name="serviceClass"

            value="demo.IHelloService" />

        <!-- Web Service名稱 -->

        <property name="name" value="HelloServiceUT"/>

    </bean>

</beans>

這樣,將項目部署到tomcat下,啓動容器,在瀏覽器中輸入http://localhost:8080/springxfire/service/HelloServiceUT?wsdl,可看見該發佈的Web Service的WSDL文件。

 

暈倒。。javaeye發文怎麼限制這麼嚴啊?稍微長一點還發不上來。。無奈,本來是一篇文章的,結果活生生被拆成三篇,剛好一節一篇,各位看的時候耐點心吧~~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章