1、 配置web.xml
见文件web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>cxf</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/classes/applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/webservice/*</url-pattern> </servlet-mapping> <!-- 字符过滤器 --> <filter> <filter-name>encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.html</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.html</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>*.3g</url-pattern> </filter-mapping> </web-app>
2、 配置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:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> <jaxws:endpoint id="helloWorld" implementor="com.hsy.server.HelloWorldImpl" address="/helloWorld" /> <bean id="client" class="com.hsy.server.HelloWorld" factory-bean="clientFactory" factory-method="create"/> <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"> <property name="serviceClass" value="com.hsy.server.HelloWorld"/> <property name="address" value="http://localhost:8080/cxf/webservice/helloWorld"/> </bean> </beans>
3、 修改客户端代码
package com.hsy.client; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import com.hsy.pojo.User; import com.hsy.server.HelloWorld; public class HelloWorldClient { /** * @param args */ public static void main(String[] args) { //Resource resource= new FileSystemResource("F:/workspaces4me2013/.metadata/.me_tcat/WEB-INF/classes/applicationContext.xml"); //BeanFactory factory= new XmlBeanFactory(resource ); ApplicationContext factory = new ClassPathXmlApplicationContext("/applicationContext.xml"); HelloWorld client = (HelloWorld)factory.getBean("client"); User user1 = new User(); user1.setName("马"); user1.setDescription("怀念马"); User user2 = new User(); user2.setName("恩"); user2.setDescription("怀念恩"); List<User> userList= new ArrayList<User>(); userList.add(user1); userList.add(user2); String[] res = client.SayHiToUserList(userList); System.out.println(res[0]); System.out.println(res[1]); } }
4、 启动tamcat发布webService
然后在浏览器输入地址:http://localhost:8080/cxf/webservice/helloWorld?wsdl
5、 运行客户端代码访问webService
右键 run as 选择java application,控制台打印
Ok,客户端访问也成功了。
此篇实现了webService服务的发布以及在本工程下的客户端调用服务的示例
相关推荐
spring集成xfire webservice实现远程调用 将项目发布后,点击http://localhost:8080/SpringWebServiceTest/services/HelloWS?wsdl即可 其中也有客户端的调用,自己试试吧。
spring mvc集成webservicedemo
spring.net整合webservice
NULL 博文链接:https://chilongxph.iteye.com/blog/510707
spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码 spring集成axis发布webservice源码
Spring集成axis2实现webservice所用到的Jar包,将所有的包放到项目的LIB目录下面
XFire与Spring集成WebService客户端的两种开发方式.pdfXFire与Spring集成WebService客户端的两种开发方式.pdfXFire与Spring集成WebService客户端的两种开发方式.pdfXFire与Spring集成WebService客户端的两种开发方式...
基于spring和CXF发布webservice,包含java本地发布和调用及web发布和调用。
spring和xfire集成的时候修要的jar文件,spring需要的jar文件自己另行下载。.
spring+axis集成webservice
使用最新的CXF2.7和Spring3的 Java WebService 集成用例 应用Spring Annotation
cxf与spring整合webservice所需jar
CXF+Spring+Hibernate实现WebService,实现的方法比较简单,只有一个增加的方法,没有用到Struts 有服务端代码和客户端测试代码
axis1.4+mybatis3+spring3集成实现webservice;websphere下Log4j记录日志解决方案;
使用spring集成cxf,在两个web project里发布及调用webservice server端使用spring+springmvc+mybatis+cxf,client端使用struts2+spring+hibernate+cxf 两个工程均为myeclipse project,包含所有除myeclipse自带以外...
在做四川电信项目时搭建的一个webservice集成spring的服务端框架,里面有服务端的实现,运行后在浏览器总输入:http://localhost:端口/ismpbJOA_me/services/BnetForJOA?wsdl 便可以看到wsdl文件,希望对大家有用
cxf集成Spring的restful WebService接口以Json形式表现的完整代码,适合新入门在学WebService的小伙伴们参考,希望对你们有帮助!
spring+xfire( 编写webservice完整配置+案例)
想了解webservice,与spring集成步骤,这个很值得才考,大家可以试试看。