Browse Source

获取服务器地址方法修改

dev_shibei_match
jianjun 4 years ago
parent
commit
3bc7126add
  1. 11
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IpUtils.java

11
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IpUtils.java

@ -12,6 +12,7 @@ import com.epmet.commons.tools.constant.StrConstant;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
@ -127,12 +128,12 @@ public class IpUtils {
* 遍历本地网卡的方式在云平台虚拟机取不到真正的ip
* @return
*/
InetAddress localAddress = InetAddress.getLocalHost();
if (isValidAddress(localAddress)) {
return localAddress.getHostAddress();
}
InetUtils inetUtils = SpringContextUtils.getBean(InetUtils.class);
if (inetUtils == null || inetUtils.findFirstNonLoopbackHostInfo() == null) {
logger.warn("Could not get local host ip address");
return null;
} else {
SERVER_IP = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
}
} catch (Exception e) {
logger.error("IpUtils getServerIp exception ", e);
}

Loading…
Cancel
Save