使用Jax-ws将webservice发布到Web容器(Tomcat)

xiaoxiao2021-02-28  5

下载jax-ws依赖包

因为tomcat没有jax-ws所需的依赖环境,所以第一步先下载Jax-ws RI,即jax-ws reference implementation, 地址:http://download.csdn.net/detail/zhangzeyuaaa/9904922

新建项目

Webservice服务类HelloWorldService:

package com.zzj.webservice; import javax.jws.WebService; @WebService public class HelloWorldService { public String sayHello(String name) { return "Hello " + name + "!"; } } 服务类HelloWorldService2同上。

web.xml:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>WebserviceOnWeb</display-name> <listener> <listener-class> com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener-class> </listener> <servlet> <servlet-name>myWebservice</servlet-name> <servlet-class> com.sun.xml.ws.transport.http.servlet.WSServlet </servlet-class> </servlet> </web-app>

注:无需为WSServlet做映射。

编写sun-jaxws.xml文件并放到WEB-INF下: <?xml version="1.0" encoding="UTF-8"?> <endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0"> <endpoint name="helloWorldService" implementation="com.zzj.webservice.HelloWorldService" url-pattern="/service/helloWorldService" /> <endpoint name="helloWorldService2" implementation="com.zzj.webservice.HelloWorldService2" url-pattern="/service/helloWorldService2" /> </endpoints>启动tomcat,访问http://localhost:8080/WebserviceOnWeb/service/helloWorldService 或者 http://localhost:8080/WebserviceOnWeb/service/helloWorldService2:

转载请注明原文地址: https://www.6miu.com/read-450331.html

最新回复(0)