新聞中心
XFire是一個簡化WebService開發(fā)的開源項目,通過Spring集成XFire可以大大簡化基于Spring Framework的應用中的WebService開發(fā)。

創(chuàng)新互聯成立與2013年,是專業(yè)互聯網技術服務公司,擁有項目成都網站建設、做網站網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元富縣做網站,已為上家服務,為富縣各地企業(yè)和個人服務,聯系電話:13518219792
Spring集成XFire可以通過多種方式結合,下文介紹的是筆者常用的一種簡單而實用的方法。所用的Spring版本為2.0,XFire版本為1.2.6。
Spring集成XFire之一:配置XFire Servlet
在web.xml中加入如下配置:
| <servlet> <servlet-name>XFireServlet</servlet-name> ?。約ervlet-class> org.codehaus.xfire.spring.XFireSpringServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>XFireServlet</servlet-name> ?。紆rl-pattern>/servlet/XFireServlet/*</url-pattern> </servlet-mapping> <servlet-mapping> ?。約ervlet-name>XFireServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> |
Spring集成XFire之二:配置Spring的監(jiān)聽器,同基于spring的Web項目一樣Spring的監(jiān)聽器是必不可少的。
| <context-param> <param-name>contextConfigLocation</param-name> ?。紁aram-value> classpath:org/codehaus/xfire/spring/xfire.xml, /WEB-INF/applicationContext.xml ?。?param-value> </context-param> <listener> ?。糽istener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> |
以下是為開發(fā)WebService而編寫的完整的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> ?。紁aram-name>contextConfigLocation</param-name> ?。紁aram-value> classpath:org/codehaus/xfire/spring/xfire.xml, /WEB-INF/applicationContext.xml ?。?param-value> ?。?context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener ?。?listener-class> </listener> <servlet> ?。約ervlet-name>XFireServlet</servlet-name> <servlet-class> org.codehaus.xfire.spring.XFireSpringServlet ?。?servlet-class> </servlet> <servlet-mapping> ?。約ervlet-name>XFireServlet</servlet-name> <url-pattern>/servlet/XFireServlet/*</url-pattern> </servlet-mapping> <servlet-mapping> ?。約ervlet-name>XFireServlet</servlet-name> ?。紆rl-pattern>/services/*</url-pattern> </servlet-mapping> </web-app> |
Spring集成XFire之三:定義接口及實現服務
定義接口,這個接口中定義要通過WebService暴露的方法
| package org.ccsoft; publicinterface HelloWS { |
實現服務
| package org.ccsoft; publicclass HelloWSImp implements HelloWS { |
Spring集成XFire之四:配置服務
將上文中實現的服務,加入到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"> <bean id="helloWS" class="org.ccsoft.HelloWSImp"/> <bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler"/> |
【編輯推薦】
- 高手Java核心技術學習筆記
- 告訴你怎樣學Java才是硬道理
- 如何獲取Sun推出的Java認證
- 共同學習Java環(huán)境變量
- JAVA環(huán)境變量的設置
網頁題目:Spring集成XFire開發(fā)WebService
標題路徑:http://m.fisionsoft.com.cn/article/cdsccds.html


咨詢
建站咨詢
