CXF+Spring搭建webservice服務示例
Apache CXF 是一個開源的 Services 框架,下面給大家講解一下如何在springmvc裡面集成cxf搭建webservice服務。
1 在maven的pom.xml裡面添加Apache CXF相關的jar包
<!-- Apache CXF for webservices start -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>2.6.16</version>
Advertisements
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.6.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
Advertisements
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.6.16</version>
<scope>compile</scope>
</dependency>
<!-- Apache CXF for webservices end -->
2在web.xml裡面添加關於Apache CXF的servlet相關配置
<!--cxf start -->
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<!--cxf end -->
3新建相關的webservice介面
4新建相關的webservice實現類
5新建cxf-servlet.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:soap="http://cxf.apache.org/bindings/soap" xmlns:cxf="http://cxf.apache.org/core"
xmlns:p="http://cxf.apache.org/policy" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/default.xsd">
<jaxws:endpoint xmlns:customer="http://claridy.lockerAdmin.webservices/"
id="LockerServiceHTTP3" address="/LockerAPI" serviceName="LockerService"
endpointName="com.claridy.webservice.ILockerService" implementor="com.claridy.webservice.LockerServiceImpl">
</jaxws:endpoint>
</beans>
6啟動項目,訪問測試網址,查看發布的webservice
http://192.168.20.140:8080/testAdmin/services/LockerAPI?wsdl
請大家多多關注我的頭條號,謝謝大家!