|
|
@ -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); |
|
|
|
} |
|
|
|