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

在发布时不要用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("发布成功!");


你可能感兴趣的:(无法用ip访问,webservice)