代码改变世界

Java 基于web service 暴露接口 供外部调用

2017-02-22 09:20  甘雨路  阅读(3480)  评论(0编辑  收藏  举报
package cn.zr.out.outinterface;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.jws.WebService;
import javax.xml.ws.Endpoint;




@WebService(name="webSer",serviceName="userWebService",targetNamespace="outws")
public class OutInterface {

    public static void main(String[] args) {
        Endpoint.publish("http://localhost:9865/", new OutInterface());
        System.out.println("=== 程序正在运行 ===");
    }
    
    public String outService(String info) {
        String msg = "暴露接口"+info;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String currentTime = format.format(new Date());
        System.out.println(msg+",调用时间:"+currentTime);
        return msg;
    }
}

然后在浏览器上输入http://localhost:9865/webSer?wsdl,会出现如下信息: