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{
    
    @Override
    public 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值