cxf+spring实现webservice
来源:互联网 发布:python客户端开发 编辑:程序博客网 时间:2024/05/19 19:42
1、构建maven项目,工程结构如下:
这里需要特别指出就是cxf-core-3.1.12.jar类路径META-INF/cxf下有一个cxf.xml的配置文件,这个在applicationContext.xml配置文件中会使用到。
2、编写pom.xml文件,这里需要引入cxf-rt-frontend-jaxws,cxf-rt-transports-http两个jar,因为要和spring整合,这里还需要引入spring的依赖。下面的pom文件已经是最精简的。
<properties> <cxf.version>3.1.12</cxf.version> <spring.version>4.2.0.RELEASE</spring.version> </properties> <dependencies> <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.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> </dependencies>
3、接口和实现类:自定义一个webservice接口BaseService并开启注解,自定义BusinessService类实现BaseService接口。
BaseService.java
package com.xxx.service;import javax.jws.WebService;@WebServicepublic interface BaseService { public int add(int a,int b); public String sayHello(String name);}BusinessService.java
package com.xxx.service.impl;import javax.jws.WebService;import com.xxx.service.BaseService;@WebService(endpointInterface="com.xxx.service.BaseService")public class BusinessService implements BaseService { @Override public int add(int a, int b) {return a+b; } @Override public String sayHello(String name) {return "hello,"+name; }}
4、web.xml配置文件
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>webservice</display-name> <context-param> <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> <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></web-app>
5、applicationContext.xml,这里需要指出的是在创建applicationContext.xml之后,在命名空间中引入jaxws,文件中需要引入一个cxf.xml文件,这个文件无需手动创建,他在cxf-core-3.1.12.jar类路径下的META-INF/cfx下。在第一步的项目结构中可以看到。
<?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://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 该文件是在cxf-core-3.1.12.jar的类路径下的META-INF/cxf/cxf.xml --> <import resource="classpath:META-INF/cxf/cxf.xml"/> <bean id="business" class="com.xxx.service.impl.BusinessService"></bean> <jaxws:endpoint id="businessService" address="/business" implementor="#business"></jaxws:endpoint></beans>
6、接口发布
阅读全文
1 0
- CXF+Spring 实现WebService
- CXF+Spring 实现WebService
- CXF+Spring实现webservice
- CXF+Spring 实现webService
- cxf+spring 实现webservice
- cxf+spring实现webservice
- CXF整合spring实现webservice
- CXF 实现webservice例子 集成spring
- CXF实现和Spring整合发布WebService
- cxf依赖spring 方式实现webservice服务端
- CXF和spring整合实现webservice实例
- spring + springmvc + cxf 实现webservice restful
- spring整合cxf实现webservice发布
- Spring框架整合CXF WebService实现原理
- CXF和spring整合实现webservice实例
- spring整合cxf实现restful webservice
- cxf+spring发布webservice
- CXF WebService整合Spring
- MyBatis中的批量操作
- linux的移动配置
- 程序执行顺序
- jQuery阻止事件冒泡
- UVA 1594
- cxf+spring实现webservice
- Ubuntu16.04设置OpenVPN服务器
- mysql-5.7.19-winx64 免安装版配置方法
- 多分支
- zookeeper伪集群启动失败失败:Invalid config, exiting abnormally
- 中国黑客六道:用代码制作两只乌龟养养
- Hibernate框架快速入门
- hdu 1240 Asteroids!
- Python3 爬虫学习(一):urllib库的使用及简单的爬取