cxf+spring实现webservice
2017-09-04 11:21
357 查看
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文件已经是最精简的。
3、接口和实现类:自定义一个webservice接口BaseService并开启注解,自定义BusinessService类实现BaseService接口。
BaseService.java
4、web.xml配置文件
5、applicationContext.xml,这里需要指出的是在创建applicationContext.xml之后,在命名空间中引入jaxws,文件中需要引入一个cxf.xml文件,这个文件无需手动创建,他在cxf-core-3.1.12.jar类路径下的META-INF/cfx下。在第一步的项目结构中可以看到。
6、接口发布
这里需要特别指出就是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; @WebService public 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.xsd http://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/ b23b 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、接口发布
相关文章推荐
- CXF整合spring实现webservice
- CXF+Spring+Hibernate实现RESTful webservice服务端实例
- CXF+Spring 实现WebService
- WebService -- Java 实现之 CXF ( 使用Spring添加拦截器)
- WebService-CXF和spring整合实现webservice案例(Spring配置注解环境)
- CXF和spring整合实现webservice实例
- CXF+Spring实现WebService
- CXF实现简单webservice应用、集成spring发布到tomcat
- CXF和spring整合实现webservice实例(二)
- Maven+SpringMVC+CXF整合实现webservice服务的发布与调用
- CXF和Spring整合实现WebService服务端、客户端
- CXF+Spring+Hibernate实现RESTful webservice服务端实例
- spring如何集成cxf实现webservice接口功能详解
- spring整合cxf实现restful webservice
- webservice之cxf实现[web项目中基于maven与spring整合]
- 在java中使用spring整合cxf实现webservice
- CXF和spring整合实现webservice实例
- strtus2 + spring + CXF 实现能访问action的同时还能调用spring发布的Webservice
- cxf整合spring实现webservice
- CXF+Spring+Hibernate实现RESTful webservice服务端实例