1.定义SEI
package com.demo.cxf.helloword; import java.util.List; import javax.jws.Oneway; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService(targetNamespace="com.demo.cxf.helloword") public interface HelloWord { String sayHello(@WebParam(name="text") String text); }
2.实现SEI
package com.demo.cxf.helloword.impl; import javax.jws.WebService; import com.demo.cxf.helloword.HelloWord; @WebService(targetNamespace="com.demo.cxf.helloword") public class HelloWordImpl implements HelloWord { @Override public String sayHello(String text) { return "Hello " + text; } }
3.服务端配置
<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-servlet.xml" /> <jaxws:endpoint id="helloWorld" implementor="com.demo.cxf.helloword.impl.HelloWordImpl" address="/HelloWorld"> </jaxws:endpoint> </beans>
4.客户端配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" 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.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:client id="helloClient" serviceClass="com.demo.cxf.helloword.HelloWord" address="http://localhost:8080/webservice/services/HelloWorld" /> </beans>
5.客户端代码
ApplicationContext context = new ClassPathXmlApplicationContext("cxf/cxf-client.xml"); HelloWord helloWord = (HelloWord)context.getBean("helloClient"); System.out.println(helloWord.sayHello("Bruce"));
6.web.xml中需要加入以下配置
<context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/cxf-servlet.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>CXF</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXF</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping>
相关推荐
使用apache cxf开发一个入门小程序
本示例只是一个cxf的简单的一个helloWorld程序,运行时先运行webServiceApp.java,再在地址栏中输入http://localhost:8080/helloWorld,如果在浏览器中有一串xml输出则成功,然后再运行HelloWorldClient.java文件...
CXF入门的经典项目,SOA实现技术之一。要学SOA,必看。
webservice-helloworld 视频 两台机器访问,一个是虚拟机。 高清
webservice-helloworld 视频 两台机器访问,一个是虚拟机。
使用CXF实现简单HelloWorld.swf 主要是让初学者学习cxf使用
NULL 博文链接:https://fengfan2008.iteye.com/blog/509342
CXF视频:1、使用CXF实现简单的HelloWorld
apache cxf 一个helloworld的例子
2.HelloWorld 3.WSDL描述 WebService CXF学习——进阶篇 1.SOAP讲解 2.JAX-WS讲解 3.对象传递 WebService CXF学习——高级篇(一)(二) 1.整合Spring框架 2.CXF+Spring+Hibernate 3.WS-Security ...
web service之第一个小demo helloworld!
CXF视频教程1 使用CXF实现简单的HelloWorld
利用CXF3.0+Spring3.2 HelloWorld实例,并且导入了小量的jar包以及在写例子的过程中遇见的一些错误!
cxf 的简单实现,maven管理,jdk1.6.
cxf实用案例代码,helloworld的基本代码,请参阅
使用CXF发布和调用webservice之HelloWorld入门使用CXF发布和调用webservice之HelloWorld入门
收藏的CXF入门文档…………. CXF与spring集成 cxf+spring+struts2的helloWorld
NULL 博文链接:https://ryxxlong.iteye.com/blog/1504896
NULL 博文链接:https://hbiao68.iteye.com/blog/1968185
CXF webservice 入门视频 很清晰很不错,企业当中很多都在使用CXF