自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Spring集成XFire開發(fā)WebService

開發(fā) 后端
Spring是目前最流行的JavaEE Framework,但是使用Spring集成XFire開發(fā)WebService卻十分繁瑣。
  XFire是一個簡化WebService開發(fā)的開源項目,通過Spring集成XFire可以大大簡化基于Spring Framework的應(yīng)用中的WebService開發(fā)。

  Spring集成XFire可以通過多種方式結(jié)合,下文介紹的是筆者常用的一種簡單而實用的方法。所用的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>
?。約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>

  Spring集成XFire之二:配置Spring的監(jiān)聽器,同基于spring的Web項目一樣Spring的監(jiān)聽器是必不可少的。

<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>
?。糽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">
?。糲ontext-param>
 ?。紁aram-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>
<servlet>
?。約ervlet-name>XFireServlet</servlet-name>
?。約ervlet-class>
  org.codehaus.xfire.spring.XFireSpringServlet
 </servlet-class>
</servlet>
<servlet-mapping>
?。約ervlet-name>XFireServlet</servlet-name>
?。紆rl-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之三:定義接口及實現(xiàn)服務(wù)

  定義接口,這個接口中定義要通過WebService暴露的方法

package org.ccsoft;

publicinterface HelloWS {
 public String sayHello(String sb);
}

  實現(xiàn)服務(wù)

package org.ccsoft;

publicclass HelloWSImp implements HelloWS {
 public String sayHello(String sb) {
  // TODO Auto-generated method stub
  return"Hello "+sb;
 }
}

  Spring集成XFire之四:配置服務(wù)

  將上文中實現(xiàn)的服務(wù),加入到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 name="helloService" class="org.codehaus.xfire.spring.ServiceBean">
<property name="serviceBean" ref="helloWS"/>
<property name="serviceClass" value="org.ccsoft.HelloWS"/>
<property name="inHandlers">
 <list>
  <ref bean="addressingHandler"/>
?。?list>
</property>
</bean>

<bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler"/>
</beans>

【編輯推薦】

  1. 高手Java核心技術(shù)學習筆記
  2. 告訴你怎樣學Java才是硬道理
  3. 如何獲取Sun推出的Java認證
  4. 共同學習Java環(huán)境變量
  5. JAVA環(huán)境變量的設(shè)置
責任編輯:王觀 來源: 天極網(wǎng)
相關(guān)推薦

2009-06-18 09:42:52

SpringXFire構(gòu)建Web

2011-11-29 10:23:47

JSPaxiswebservice

2014-11-18 11:20:51

webserviceCXFSpring

2015-07-09 10:44:48

C#WebService

2009-09-22 17:55:51

Spring Hibe

2009-06-30 17:03:49

Spring集成Str

2009-06-23 13:21:26

JSF和Spring

2009-06-17 15:18:38

JSF與Spring

2009-06-19 15:52:58

Struts和Spri

2009-04-01 16:46:31

問題開發(fā)WebService

2023-01-10 07:52:15

2009-06-22 10:29:11

集成測試Spring

2018-11-02 15:45:41

Spring BootRedis數(shù)據(jù)庫

2020-07-14 11:00:12

Spring BootRedisJava

2009-06-19 16:25:34

Flex與Spring

2019-12-03 11:00:08

spring bootspring-kafkJava

2011-04-26 09:13:15

webservice

2009-08-13 15:16:00

Eclipse建立We

2009-06-18 15:56:49

Struts和Spri

2009-06-01 16:18:30

SpringJPA集成
點贊
收藏

51CTO技術(shù)棧公眾號