Java创建WebService

从java 6之后就提供了简单快速的创建WebService的方法,这里将这种简单的方法记录下来方便以后回看。
第一步:首先创建一个java Project,然后创建一个类HelloWorldImpl如下:

package com.service.impl;

import javax.jws.WebService;

//@WebService用于标识该类为WebService类
@WebService
public class HelloWorldImpl {
    public String sayHello(String text) {
        return "Hello : " + text;
    }
}

第二步:创建一个主函数类,如下:

package com.service;

import javax.xml.ws.Endpoint;
import com.service.impl.HelloWorldImpl;

public class App {
    public static void main(String[] args) {
        String address = "http://127.0.0.1:8099/HelloWorld";
        Endpoint.publish(address, new HelloWorldImpl());
        System.out.println("发布消息成功");
    }
}

第三步:直接运行当前这个主方法,然后在浏览器输入如下地址即可验证是否成功:
http://127.0.0.1:8099/HelloWorld?wsdl

原文地址:https://www.cnblogs.com/duanjt/p/7977509.html