Web service是一個平臺獨立的,低耦合的,自包含的、基於可編程的web的應用程序,可以使用開放的XML標準來描述、發佈、發現、協調和配置這些應用程序,用於開發分佈式的互操做的應用程序。 html
網絡服務描述語言是一個用來描述Web服務和說明如何與Web服務通訊的XML(標準通用標記語言的子集)語言。爲用戶提供詳細的接口說明書。 java
簡單對象訪問協議是交換數據的一種協議規範,是一種輕量的、簡單的、基於XML(標準通用標記語言下的一個子集)的協議,它被設計成在WEB上交換結構化的和固化的信息。 web
一種 Java 規範,名爲 JAX-WS(JSR-224),全稱 Java API for XML-Based Web Services,能夠將規範理解爲官方定義的一系列接口。 spring
爲了讓 WS 的開發與使用變得更加簡單、更加輕量級,因而出現了另外一種風格的 WS,名爲 JAX-RS(JSR-339),全稱 Java API for RESTful Web Services,一樣也是一種規範,一樣也有若干實現,cxf是其中比較著名的一種。 apache
剛入行的時候一直把cxf當作webservice,其實cxf只是發佈調用webservice的工具而已。 編程
因爲webservice有基於soap的實現和rest的實現,這使得cxf的maven配置比較混亂。 json
<!-- cxf config begin --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>2.7.3</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>2.7.3</version> </dependency> <!-- cxf config end -->
<!-- JSON begin --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-jaxb-annotations</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json-provider</artifactId> <version>${jackson.version}</version> <!-- Jackson2.2.0 版本對於 CXF2.7.3 不支持 --> <!-- http://www.marshut.com/krrqx/fasterxml-jackson-2-2-provider-no-longer-works-with-cxf-jax-rs.pdf --> <!-- http://cxf.547215.n5.nabble.com/Creating-input-values-on-WADL-td5728910.html --> </dependency> <!-- Spring WebMVC 3.1.2 用到 --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.0</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>1.9.0</version> </dependency> <!-- JSON end -->
後面兩個依賴視你的spring版本狀況而定。 api
package com.winssage.winssagebpm.application; import javax.jws.WebService; import com.winssage.winssagebpm.baseapplication.IBaseApplication; import com.winsssage.winssagebpm.domain.User; @WebService public interface UserApplication extends IBaseApplication<User> { public String sayHello( String name); }
package com.winssage.winssagebpm.applicationImpl; import javax.inject.Named; import javax.jws.WebService; import org.springframework.transaction.annotation.Transactional; import com.winssage.winssagebpm.application.UserApplication; import com.winssage.winssagebpm.baseapplicationImpl.BaseApplicationImpl; import com.winsssage.winssagebpm.domain.User; @WebService(endpointInterface = "com.winssage.winssagebpm.application.UserApplication") @Named("userApplication") @Transactional public class UserApplicationImpl extends BaseApplicationImpl<User> implements UserApplication { public String sayHello(String name) { name = "hello" + name; return name; } }
#userApplication爲實現中註解進來的bean. 網絡
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath*:META-INF/cxf/cxf.xml" /> <import resource="classpath*:META-INF/cxf/cxf-servlet.xml" /> <jaxws:endpoint id="security" implementor="#userApplication" address="/user" /> </beans>
<bean id="userServiceClient" class="com.winssage.winssagebpm.application.UserApplication" factory-bean="userServiceClientFactory" factory-method="create"/> <bean id="userServiceClientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"> <property name="serviceClass" value="com.winssage.winssagebpm.application.UserApplication"/> <property name="address"> <value>http://localhost:9080/winssagebpm-web/api/user</value> </property> </bean>
詳見http://my.oschina.net/fengshuzi/blog/280408 app