jax-ws实现WebService
生活随笔
收集整理的這篇文章主要介紹了
jax-ws实现WebService
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
關于WebService有很多框架了,CXF,Spring自己的webservice等等,因為cxf實際也是依賴spring的servlet,這里說明一下jax-ws,使用原生的servlet實現。
比較簡單,maven3+servlet3,servlet3不需要在web.xml中配置servlet了,直接貼代碼了
maven依賴:
<dependency><groupId>com.sun.xml.ws</groupId><artifactId>jaxws-rt</artifactId><version>2.2.10</version></dependency><dependency><groupId>javax.xml.ws</groupId><artifactId>jaxws-api</artifactId><version>2.2.11</version></dependency><dependency><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-core</artifactId><version>2.2.11</version></dependency><dependency><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-impl</artifactId><version>2.2.11</version></dependency><dependency><groupId>com.sun.xml.stream.buffer</groupId><artifactId>streambuffer</artifactId><version>1.5.3</version></dependency><dependency><groupId>com.sun.xml.ws</groupId><artifactId>policy</artifactId><version>2.5</version></dependency><dependency><groupId>org.glassfish.gmbal</groupId><artifactId>gmbal-api-only</artifactId><version>3.2.0-b003</version></dependency><dependency><groupId>org.glassfish.ha</groupId><artifactId>ha-api</artifactId><version>3.1.9</version></dependency><dependency><groupId>org.jvnet.staxex</groupId><artifactId>stax-ex</artifactId><version>1.7.7</version></dependency>本篇文檔不解釋細節,先把webservice起來再說,WEB-INF下添加sun-jaxws.xml
<?xml version="1.0" encoding="UTF-8"?> <endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0"><endpoint name="hello" implementation="com.star.HelloImpl" url-pattern="/services/hello" /> </endpoints>下面寫最簡單的HelloWorld
import javax.jws.WebService;/*** WebService接口*/ @WebService public interface McSendSMS {public String sayHello(String name);} import javax.jws.WebService;@WebService(endpointInterface = "com.star.Hello") public class HelloImpl implements Hello{@Overridepublic String sayHello(String name) {System.out.pring("666")return "hello" + name;} }接下來直接發布,jetty,tomcat隨便,這里使用jetty,好了,訪問路徑:http://localhost:8888/services/hello,客戶端直接根據wsdl地址生成就OK。
喜歡請關注微信公眾號:碼農小麥
轉載于:https://www.cnblogs.com/render-inside/p/6029339.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的jax-ws实现WebService的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML转义字符 Unicode和CSS
- 下一篇: 搜索引擎Solr系列(二): Solr6