//首先打开Myeclipse8.x以上版本..因为我这里共享那些xfire 项目所需要的jar都是Myeclipse自带添加的,所以要求大家伙准备好myeclipse8.x或者更高版本的..这里是spring2.0与xfire1.2整合..废话少说..转正正传.. 1.打开Myeclipse--->new project-->项目名随便吧..最好是有意义的名称..看起来比较舒服.. 2--配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml,classpath:org/codehaus/xfire/spring/xfire.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <servlet> <servlet-name>XFireServlet</servlet-name> <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>XFireServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
3.配置applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd" default-autowire="byName" default-lazy-init="true" > <import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/> <import resource="xfire-servlet.xml"/> </beans>
4.配置xfire-servlet.xml //为了不给大家伙困扰.所以我这里用那个就打开那个配置..
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> <!-- <bean id="HellWorldSimple" class="org.codehaus.xfire.spring.ServiceBean"> <property name="name"> <value>HelloWorldSimple</value> </property> <property name="namespace"> <value>http://service.core.xfire.com</value> </property> <property name="serviceClass"> <value>com.xfire.core.service.IHelloWorld</value> </property> <property name="serviceBean"> <ref bean="HellWorldSimple"/> </property> </bean> --> <!-- <bean id="MyHandle" class="org.codehaus.xfire.spring.ServiceBean"> <property name="name"> <value>MyHandle</value> </property> <property name="namespace"> <value>http://service.core.xfire.com</value> </property> <property name="serviceClass"> <value>com.xfire.core.handler.MyHandlerImpl</value> </property> <property name="serviceBean"> <ref bean="MyHandle"/> </property> </bean> --> <bean id="UserInfoService" class="org.codehaus.xfire.spring.ServiceBean"> <property name="name"> <value>UserInfo</value> </property> <property name="namespace"> <value>http://service.core.xfire.com/UserInfoService</value> </property> <property name="serviceClass"> <value>com.xfire.core.service.IUserInfoService</value> </property> <property name="serviceBean"> <ref bean="UserInfoService"/> </property> </bean> <!-- <bean id="ApplictionException" class="org.codehaus.xfire.spring.ServiceBean"> <property name="name"> <value>ApplictionException</value> </property> <property name="namespace"> <value>http://service.core.xfire.com/IMyExceptionSevice</value> </property> <property name="serviceClass"> <value>com.xfire.core.service.IMyExceptionSevice</value> </property> <property name="serviceBean"> <ref bean="ApplictionException"/> </property> </bean> --> <!-- <bean id="IServiceMap" class="org.codehaus.xfire.spring.ServiceBean"> <property name="name"> <value>AddressService</value> </property> <property name="namespace"> <value>http://service.core.xfire.com/IServiceMap</value> </property> <property name="serviceClass"> <value>com.xfire.core.service.IServiceMap</value> </property> <property name="serviceBean"> <ref bean="IServiceMap"/> </property> </bean> --> </beans>
5.xfire-servlet.xml配置
<?xml version="1.0" encoding="UTF-8"?> <beans> <!-- 在没整合spring之前的xfire是这样的配置 当要整合spring之后的这句代码复制到service 节点 xmlns="http://xfire.codehaus.org/config/1.0" <beans xmlns="http://xfire.codehaus.org/config/1.0"> --> <service xmlns="http://xfire.codehaus.org/config/1.0"> <name>UserInfo</name> <namespace>http://service.core.xfire.com</namespace> <serviceClass>com.xfire.core.service.IUserInfoService</serviceClass> <implementationClass>com.xfire.core.service.impl.UserInfoServiceImpl </implementationClass> <scope>request</scope> <!-- <name>HelloWorldSimple</name> <namespace>http://service.core.xfire.com</namespace> <serviceClass>com.xfire.core.service.IHelloWorld</serviceClass> <implementationClass>com.xfire.core.service.impl.HelloWorldImpl</implementationClass> <style>wrapped</style> <use>literal</use> <scope>request</scope> --> <!-- <name>MyHandle</name> <namespace>http://service.core.xfire.com</namespace> <serviceClass>com.xfire.core.handler.IMyHandler</serviceClass> <implementationClass>com.xfire.core.handler.MyHandlerImpl</implementationClass> <scope>application</scope> --> <!-- <name>ServiceMap</name> <namespace>http://service.core.xfire.com</namespace> <serviceClass>com.xfire.core.service.IServiceMap</serviceClass> <implementationClass>com.xfire.core.service.impl.ServiceMapImpl </implementationClass> <scope>request</scope> --> <!-- <name>ApplictionException</name> <namespace>http://service.core.xfire.com</namespace> <serviceClass>com.xfire.core.service.IMyExceptionSevice</serviceClass> <implementationClass>com.xfire.core.service.impl.MyExceptionSeviceImpl</implementationClass> <scope>request</scope> --> </service> </beans>
实现代码..首先新建一个实体类UseInfor package com.xfire.core.entity; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; /** *@author jilongliang *@Date 2012-2-29 */ @ SuppressWarnings("all")public class UserInfo implements Serializable { private Integer identifier; private String address; private String city; private String proivice; public Integer getIdentifier() { return identifier; } public void setIdentifier(Integer identifier) { this.identifier = identifier; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getProivice() { return proivice; } public void setProivice(String proivice) { this.proivice = proivice; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public String getPostCode() { return postCode; } public void setPostCode(String postCode) { this.postCode = postCode; } public String[]getArrary() { return arrary; } public void setArrary(String[]arrary) { this.arrary = arrary; } public List < Integer > getList() { return list; } public void setList(List < Integer > list) { this.list = list; } public Map < Integer, InnerClass > getMap() { return map; } public void setMap(Map < Integer, InnerClass > map) { this.map = map; } public boolean isExist() { return isExist; } public void setExist(boolean isExist) { this.isExist = isExist; } public InnerClass getInner() { return inner; } public void setInner(InnerClass inner) { this.inner = inner; } private String country; private String postCode; private String[]arrary; private List < Integer > list; private Map < Integer, InnerClass > map; private boolean isExist; private InnerClass inner; public UserInfo() { list = new ArrayList < Integer > (); list.add(1); list.add(2); list.add(3); map = new HashMap < Integer, InnerClass > (); map.put(1, new InnerClass("a")); map.put(2, new InnerClass("b")); map.put(3, new InnerClass("c")); inner = new InnerClass(); inner.setInnerName("服务器地址: Address InnerClass"); } @ Override public String toString() { return "Address [address=" + address + ", arrary=" + Arrays.toString(arrary) + ", city=" + city + ", country=" + country + ", identifier=" + identifier + ", inner=" + inner + ", isExist=" + isExist + ", list=" + list + ", map=" + map + ", postCode=" + postCode + ", proivice=" + proivice + "]"; } } //----内置实体类 package com.xfire.core.entity; import java.io.Serializable; /** *@Project *@author jilongliang *@Date 2012-2-29 *@Class InnerClass.java */ @ SuppressWarnings("all")public class InnerClass implements Serializable { private String innerName = "static InnerClass"; public String getInnerName() { return innerName; } public void setInnerName(String innerName) { this.innerName = innerName; } public InnerClass() {} public InnerClass(String innerName) { super(); this.innerName = innerName; } } //其次一个接口类 : package com.xfire.core.service; import java.util.List; import com.xfire.core.entity.UserInfo; /** *@author jilongliang *@Date 2012-2-29 */ public interface IUserInfoService { public List < UserInfo > getAddressList(); public List < UserInfo > setAddresses(List < UserInfo > list); } //然后新建一个实现类去实现接口 package com.xfire.core.service.impl; import java.util.ArrayList; import java.util.List; import com.xfire.core.entity.UserInfo; import com.xfire.core.service.IUserInfoService; /** *@author jilongliang *@Date 2012-2-29 */ public class UserInfoServiceImpl implements IUserInfoService { private int requestCount = 0; public List < UserInfo > getAddressList() { requestCount++; System.out.println("requestCount" + requestCount); List < UserInfo > listAdd = new ArrayList < UserInfo > (); UserInfo address = new UserInfo(); address.setIdentifier(1); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress("廣東陽春"); address.setPostCode("1111111"); address.setExist(false); address.setArrary(new String[]{ "22", "23", "24" }); listAdd.add(address); address.setIdentifier(2); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress("廣東陽春"); address.setPostCode("1111111"); address.setExist(false); address.setArrary(new String[]{ "a", "b", "c" }); listAdd.add(address); return listAdd; } public List < UserInfo > setAddresses(List < UserInfo > list) { requestCount++; System.out.println("requestCount" + requestCount); return list; } } //客户端 package com.xfire.core.client; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; import com.xfire.core.entity.UserInfo; import com.xfire.core.service.IUserInfoService; /** *@author jilongliang * @Date 2012-3-5 * */ public class UserInfoClient { public static void main(String[]args) { getServiceList(); setServiceList(); } static String url = "http://localhost:8081/xfire/services/UserInfo"; public static void getServiceList() { Service service = new ObjectServiceFactory().create(IUserInfoService.class); try { IUserInfoService iAddressService = (IUserInfoService)new XFireProxyFactory().create(service, url); List < UserInfo > list = (ArrayList < UserInfo > )iAddressService.getAddressList(); System.out.println("一共多少条数据:" + list.size()); for (Iterator < UserInfo > iter = list.iterator(); iter.hasNext(); ) { UserInfo a = iter.next(); System.out.println(a); } } catch (MalformedURLException e) { e.printStackTrace(); } } public static void setServiceList() { Service service = new ObjectServiceFactory().create(IUserInfoService.class); try { IUserInfoService iAddressService = (IUserInfoService)new XFireProxyFactory().create(service, url); List < UserInfo > listAdd = new ArrayList < UserInfo > (); UserInfo address = new UserInfo(); address.setIdentifier(1); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress("廣東陽春"); address.setPostCode("1111111"); address.setExist(false); address.setArrary(new String[]{ "22", "23", "24" }); listAdd.add(address); address.setIdentifier(2); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress("廣東陽春"); address.setPostCode("1111111"); address.setExist(false); address.setArrary(new String[]{ "a", "b", "c" }); listAdd.add(address); List < UserInfo > returnAdd = iAddressService.setAddresses(listAdd); System.out.println("总数:" + returnAdd); for (Iterator < UserInfo > it = returnAdd.iterator(); it.hasNext(); ) { UserInfo address2 = it.next(); System.out.println(address2); } } catch (MalformedURLException e) { e.printStackTrace(); } } }
图解----
相关推荐
在这个“webservice xfire spring2.0完整实例”中,我们将会探讨如何结合XFire 1.2.6和Spring 2.0来创建和消费Web服务。首先,我们需要理解Spring 2.0中的Web服务抽象层,即Spring Web Services模块。这个模块提供了...
标题中的“xfire+spring+maven构建webservice服务器和客户端”揭示了本教程将围绕三个主要技术进行讨论:XFire、Spring和Maven。这三者都是Java开发中不可或缺的工具,尤其在构建Web服务方面。 XFire是早期的一个...
标题中的“xfire+spring+webservice+client”是一个关于集成XFire、Spring框架和Web服务客户端的专题,这涉及到Java开发中的一项重要技术——Web服务的消费与提供。在这个主题下,我们将深入探讨以下几个核心知识点...
在本文中,我们将探讨XFire与Spring框架集成以实现WebService客户端的两种开发方式。XFire是一个流行的Java Web服务实现库,而Spring是一个广泛使用的应用程序框架,可以方便地管理和配置Web服务客户端。 ### 方式...
集成XFire与Spring2,我们可以利用Spring的容器管理服务实例,以及它的强大配置能力,来更方便地管理和部署Web服务。下面将详细解释这个集成过程中的关键步骤和知识点: 1. **配置Spring容器**: 在Spring配置文件...
1. **Spring与Web服务集成**:Spring框架提供了多种集成Web服务的方式,包括使用Spring-WS、Apache CXF和曾经的XFire。XFire作为早期的选项,允许开发者轻松地在Spring应用中创建和消费Web服务,通过Aegis绑定来映射...
**Xfire开发Web服务与Java Web集成实例** 在软件开发中,Web服务是一种基于标准的、平台无关的方式,使得不同的应用程序之间能够交换数据和协同工作。Xfire是早期的一个流行的Web服务框架,它允许开发者快速地创建...
《XFire、Spring与Web服务集成的深度解析》 在当今的软件开发中,Web服务已经成为企业级应用间通信的重要手段。XFire、Spring和Web服务的结合为开发者提供了强大的工具,使得构建、部署和管理Web服务变得更为简便。...
XFire可以很好地与Spring框架集成,通过Spring的依赖注入和AOP特性,可以进一步简化Web服务的开发和管理。 六、XFire的优势与局限 虽然XFire提供了快速开发Web服务的能力,但随着技术的发展,它逐渐被更全面的...
总之,"xfire与spring集成案例"是一个实用的教程,旨在帮助开发者理解和实践如何在Spring环境中利用XFire构建Web服务。这个案例提供了完整的流程,从配置到测试,对于初学者来说是一个很好的学习起点,同时也为有...
本篇文章将深入探讨如何利用XFire与Spring的组合来发布Web服务,并提供具体的实例和所需资源。 首先,XFire(现在称为Apache CXF的一部分)是一个轻量级的Web服务框架,它支持SOAP、RESTful等多种Web服务协议,并且...
XFire的Spring集成允许开发者在Spring配置文件中声明Web服务,从而利用Spring的依赖注入特性管理Web服务实例。这使得Web服务的生命周期和管理与Spring容器无缝融合,提高了代码的可测试性和可维护性。 **创建Web...
2. XFire相关的jar文件:如`xfire-core`, `xfire-aegis`, `xfire-annotations`, `xfire-spring`等,它们提供了Web服务的实现和与Spring的集成支持。 在Spring配置中,我们可以通过以下步骤来配置XFire: 1. 引入...
Spring框架是Java企业级应用开发的首选平台,而xFire(现在称为Cxf)是一个开源的Web服务框架,它与Spring紧密集成,提供了一种简单、高效的方式来创建和消费Web服务。在这个"xFire+Spring WebService示例"中,我们...
1. **依赖注入(Dependency Injection)**:Spring 的核心特性之一,通过依赖注入可以轻松地管理 XFire 的服务实例,提高代码的可测试性和可维护性。 2. **AOP(面向切面编程)**:Spring 的 AOP 支持允许在服务层...
【xfire+Spring+WebService 入门实例详解】 在IT行业中,Web服务是一个重要的通信方式,它允许不同系统间的应用程序进行数据交换。本入门实例将深入探讨如何使用XFire框架与Spring集成来构建和消费Web服务。XFire是...
### 使用XFire与Spring开发WebService的关键知识点 #### 实现功能与特点 - **基于J2EE平台的WebService服务**:这种服务充分利用了Java 2 Platform, Enterprise Edition (J2EE)的强大特性,如事务管理、安全性等,...