소스 검색

ip 地址自动获取

hurugang 5 년 전
부모
커밋
7130e30179
1개의 변경된 파일12개의 추가작업 그리고 4개의 파일을 삭제
  1. 12 4
      src/main/java/cn/hnthyy/thmz/ThmzApplication.java

+ 12 - 4
src/main/java/cn/hnthyy/thmz/ThmzApplication.java

@@ -8,6 +8,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
 
 import javax.xml.ws.Endpoint;
+import java.net.InetAddress;
 
 @SpringBootApplication
 @Slf4j
@@ -18,10 +19,17 @@ public class ThmzApplication extends SpringBootServletInitializer {
         SpringApplication.run(ThmzApplication.class, args);
 
         //发布webservice服务
-        String address = "http://127.0.0.1:7611/webService/criticalWebService";
-        //发布WebService,WebServiceImpl类是WebServie接口的具体实现类
-        Endpoint.publish(address, new CriticalWebServiceImpl());
-        System.out.println("使用WebServicePublishListener发布webservice成功!");
+        try {
+            InetAddress ia=InetAddress.getLocalHost();
+            String localip=ia.getHostAddress();
+            String address = "http://"+localip+":7611/webService/criticalWebService";
+            //发布WebService,WebServiceImpl类是WebServie接口的具体实现类
+            Endpoint.publish(address, new CriticalWebServiceImpl());
+            System.out.println("使用WebServicePublishListener发布webservice成功!");
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
     }
 
     @Override//为了打包springboot项目