webservice只能用localhost访问,无法用ip地址访问的解决办法

时间:2022-07-08 19:11:00

在发布时不要用localhost+端口发布,发布时获取下服务器的IP地址

InetAddress address = null; try {
    address = InetAddress.getLocalHost(); } catch (UnknownHostException e) {
    e.printStackTrace(); }
String hostAddress = address.getHostAddress(); Endpoint.publish("http://"+hostAddress+":8089/test", new WebService()); System.out.println("发布成功!");