CXF框架快速应用
来源:互联网 发布:淘宝线上推广合同范本 编辑:程序博客网 时间:2024/05/21 13:56
maven依赖jar包
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>${cxf-version}</version></dependency><dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>${cxf-version}</version></dependency><dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-core</artifactId> <version>${cxf-version}</version></dependency>
Spring配置
applicationContext.xml
<!-- 设置spring的环境 --> <context-param> <!--contextConfigLocation是不能修改的 --> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
web.xml
<!--Spring路径 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
- CXF发布SOAP协议的服务
web.xml
<!-- 配置CXF --><servlet> <servlet-name>CXF</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class></servlet><servlet-mapping> <servlet-name>CXF</servlet-name> <url-pattern>/ws/*</url-pattern></servlet-mapping>
配置applicationContest.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" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> <!-- <jaxws:server发布SOAP协议的服务 ,对JaxWsServerFactoryBean类封装--> <jaxws:server address="/weather" serviceClass="cc.ws.server.WeatherService"> <jaxws:serviceBean> <ref bean="weatherServiceImpl"/> </jaxws:serviceBean> </jaxws:server> <!-- 配置服务实现类 --> <bean name="weatherServiceImpl" class="cc.ws.server.WeatherServiceImpl"></bean> <!-- <jaxws:client实现客户端 ,对JaxWsProxyFactoryBean类封装--> <jaxws:client id="weatherClient" address="http://192.168.211.129:8080/ws_cxf_spring_server-0.0.1-SNAPSHOT/ws/weather" serviceClass="cc.ws.server.WeatherService" /></beans>
服务端@WebService
客户端
ApplicationContext context = new ClassPathXmlApplicationContext("/WEB-INF/applicationContext.xml"); WeatherService weatherService = (WeatherService) context.getBean("weatherClient"); String result = weatherService.queryWeather("广州");
- CXF发布REST的服务
pojo类:
@XmlRootElement(name=”student”)//@XmlRootElement可以实现对象和XML数据之间的转换
SEI接口:
@WebService
@Path(“/Student”)
抽象方法:
@GET//指定请求方式,如果服务端发布的时候指定的是GET(POST),那么客户端访问时必须使用GET(POST)
@Produces(MediaType.APPLICATION_XML)//指定服务数据类型
@Path(“/query/{id}”)//@Path(“/query/{id}”)就是将“/query”映射到方法上,“{id}”映射到参数上,多个参数,以“/”隔开,放到“{}”中
public Student query(@PathParam(“id”)long id);
配置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" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"><!-- <jaxrs:server发布REST的服务 ,对JAXRSServerFactoryBean类封装--> <jaxrs:server address="/user"> <jaxrs:serviceBeans> <ref bean="studentInterface"/> </jaxrs:serviceBeans> </jaxrs:server> <!-- 配置服务实现类 --> <bean name="studentInterface" class="cn.itcast.ws.rest.server.StudentInterfaceImpl"/></beans>
配置web.xml
<!-- 配置CXF的Servlet --> <servlet> <servlet-name>CXF</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CXF</servlet-name> <url-pattern>/ws/*</url-pattern> </servlet-mapping>
ps:
获取wsdl使用
wsdl2java -d 存放java文件地址 wsdl地址
0 0
- CXF框架快速应用
- webservice应用 cxf框架
- 力所能及之webservice CXF框架的应用
- WebService之CXF框架应用上篇
- WebService之CXF框架应用中篇
- WebService之CXF框架应用后篇
- CXF框架
- CXF框架
- CXF框架
- CXF 应用
- 快速上手使用CXF
- 快速上手使用CXF
- 快速上手使用CXF
- 快速上手使用CXF
- Ext js 框架快速集成当前应用
- QT框架中快速应用OpenCV
- QT框架中快速应用OpenCV
- QT 框架中快速应用OpenCV
- 206. Reverse Linked List
- 自动化测试体系如何建立?(一)
- Struts2 怎么重新添加支持?
- xgboost
- android一个月培训心得
- CXF框架快速应用
- 浅谈Java中的System.gc()的工作原理
- 手动图片轮播
- JavaScript学习
- Vim的强大配置文件(一键配置)
- 安卓笔记之《第一次运行程序进入引导页面的实现》
- python下实现汉诺塔
- Ubuntu输入su提示认证失败的解决方法
- Android实现录屏直播(二)需求才是硬道理之产品功能调研