一.webService介绍
之前的文章我介绍了cxf webService的使用,它是一种以wsdl发布的形式。下面结合我在了解说明下两组概念:
jax-ws 全称:JavaTM API forXML-Based Web Services ,实现基于soap协议的Web Service提供的API,SOAP:简单对象访问协议,它是交换数据的一种协议规范,是一种轻量的、简单的、基于XML(标准通用标记语言下的一个子集)的协议,
它被设计成在WEB上交换结构化的和固化的信息。
jax-rs 全称: JavaTM API for RESTful Web Services, 基于REST设计风格的WebServcice提供的API。它是一个Java 编程语言的应用程序接口,支持按照表述性状态转移(REST)架构风格创建Web服务。
二.jax-ws 和 jax-rs 的应用场景
jax-ws 是一套标准的soap协议,他是跨语言平台的,可移植性较高,目前在webService服务中是主流,通过服务端发布wsdl格式的xml文件,供客户端访问。
jax-rs 是一套java 编程的应用程序风格,那他就不具备夸平台性,移植性单一。但是目前主流的访问都趋向于rest风格,和springMVC无缝衔接,同时它为dubbo提供了接近透明的REST调用支持。
三.搭建 jax-rs web服务
这个案例是基于我前两篇jax-ws的基础上写的,没有我之前的webService案例的小伙伴,戳这里阅读
http://www.cnblogs.com/sumingk/articles/6069220.html
http://www.cnblogs.com/sumingk/articles/6069490.html
1.这是jax-rs xml文件配置,与ws的发布风格很类似,calss指定Service的地址,address为发布的范围地址,
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans 3 xmlns="http://www.springframework.org/schema/beans" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xmlns:p="http://www.springframework.org/schema/p" 6 xmlns:tx="http://www.springframework.org/schema/tx" 7 xmlns:aop="http://www.springframework.org/schema/aop" 8 xmlns:jaxws="http://cxf.apache.org/jaxws" 9 xmlns:jaxrs="http://cxf.apache.org/jaxrs" 10 xsi:schemaLocation="http://www.springframework.org/schema/beans 11 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 12 http://www.springframework.org/schema/tx 13 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 14 http://www.springframework.org/schema/aop 15 http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 16 http://cxf.apache.org/jaxws 17 http://cxf.apache.org/schemas/jaxws.xsd 18 http://cxf.apache.org/jaxrs 19 http://cxf.apache.org/schemas/jaxrs.xsd"> 20 21 <bean id="userImpl" class="com.hdjf.app.me.impl.UserServiceImpl" /> 22 <jaxrs:server id="userServer" address="/userCxf"> 23 <jaxrs:serviceBeans> 24 <ref bean="userImpl"/> 25 </jaxrs:serviceBeans> 26 </jaxrs:server> 27 28 29 </beans>