WebService系列博客{十}[CXF简单案例实现]
来源:互联网 发布:python基础教程廖雪峰 编辑:程序博客网 时间:2024/06/06 06:56
概述:
CXF是Apache的一个Web Service框架。搭配Jax-Ws使用将部署好的web service发布到tomcat容器中
简单案例:
1、 首先准备好Jar包。可以到apache的官网下载
2、 将下载好的Jar包一次性导入到项目目录[WEB-INF/lib]文件夹下面
3、 解压lib里面的cxf.jar文件,将解压目录下面的[META-INF/cxf]copy到项目的META-INF下面
4、 编写web service接口
@WebService(name = "CxfTester", targetNamespace = "http://org.cxf.com/")public interface CxfTester { public String sendMessage(String sendTo,String message);}
5、 编写服务接口实现类
@WebService(endpointInterface = "com.cxf.org.CxfTester")public class CxfTesterImpl implements CxfTester {@Overridepublic String sendMessage(String sendTo, String Message) {String str = "发送到:" + sendTo + "信息详情:" + Message;return str;}}
6、 在WEB-INF/建立一个文件夹名为classes。并且新建一个xml文件、名为application
Context.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"> <!-- 导入cxf.jar解压出来的文件 --> <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"/><!-- 声明Endpoint, address 为访问地址的部分地址implementor 为实现类 --><jaxws:endpoint id="CxFTester" address="/CxfTester" implementor="com.cxf.org.CxfTesterImpl"/><!-- 指定客户端访问相关情况class 服务端接口factory-bean 引用下面声明的类factory-method 客户端生成调用对象所用方法--><bean id="client" class="com.cxf.org.CxfTester"factory-bean="clientFactory"factory-method="create"></bean><!-- 配置CXF服务代理beanserviceClass : 服务端接口address : 访问地址jaxws:endpoint声明的address在项目名的后面,此处的路径和web.xml配置的urlpattern有联系 --><bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"><property name="serviceClass" value="com.cxf.org.CxfTester"></property><property name="address" value="http://192.168.1.104:8080/Apache_CXF_1/CxfTester"></property></bean>
7、 编辑web.xml,设置容器启动加载applicationContext.xml文件。并且配置CXFServlet
<?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>Apache_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> <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>/*</url-pattern> </servlet-mapping></web-app>
8、 发布项目、启动tomcat并且访问wsdl文件
http://localhost:8080/Apache_CXF_1/CxfTester?wsdl
源码下载地址:
http://pan.baidu.com/share/link?shareid=216475&uk=1997312776
- WebService系列博客{十}[CXF简单案例实现]
- WebService系列博客{十}[CXF简单案例实现]
- WebService系列博客{十一}[CXF整合spring实际案例]
- 简单的WebService实现- cxf
- cxf 实现webservice 案例(转)
- WebService系列博客{七}[Schema简单案例阐述、DTD的简单阐述]
- webService 使用CXF 实现简单的helloworld
- 简单的Jax-WS WebService实现-cxf
- webservice使用CXF的简单实现
- CXF简单WebService例子
- CXF简单WebService例子
- axis2实现Webservice独立部署简单案例
- WebService-CXF和spring整合实现webservice案例(Spring配置注解环境)
- cxf实现soap webservice
- CXF+Spring 实现WebService
- Apache CXF实现WebService
- CXF+Spring 实现WebService
- CXF完整实现WebService
- 利用脚本解放自己,让脚本帮我做事2 -- 帮自己寻找不在SVN控制中的文件
- give two sorted array, find the k-th smallest element of union of A and B
- 求一个学院教材管理系统
- WEB压力测试
- OCX--VC2005开发OCX
- WebService系列博客{十}[CXF简单案例实现]
- 关于软件测试的问与答(与神仙的对话)
- boost日期、时间操作
- 初步解决ecryptfs加密ubuntu主目录的问题了
- Process组件的使用
- java读取本地文本文件
- Android录制视频(五)
- android: activity之间传递复杂数据类型[使用Serializable序列化或者Parcelable序列化]
- Android Debug Bridge命令