Use getFirstNonLoopbackAddress() from cloud commons

This commit is contained in:
Rafael Zanella
2015-12-16 16:24:34 -02:00
parent 6858a3d294
commit 6706738be9
2 changed files with 1 additions and 24 deletions

View File

@@ -16,7 +16,7 @@
package org.springframework.cloud.consul.discovery;
import static org.springframework.cloud.consul.discovery.IpAddressUtils.getFirstNonLoopbackAddress;
import static org.springframework.cloud.util.InetUtils.getFirstNonLoopbackAddress;
import java.net.InetAddress;
import java.util.ArrayList;

View File

@@ -43,27 +43,4 @@ public class IpAddressUtils {
}
return service.getNode();
}
@SneakyThrows
public static InetAddress getFirstNonLoopbackAddress() {
try {
for (Enumeration<NetworkInterface> enumNic = NetworkInterface.getNetworkInterfaces();
enumNic.hasMoreElements(); ) {
NetworkInterface ifc = enumNic.nextElement();
if (ifc.isUp()) {
for (Enumeration<InetAddress> enumAddr = ifc.getInetAddresses();
enumAddr.hasMoreElements(); ) {
InetAddress address = enumAddr.nextElement();
if (address instanceof Inet4Address && !address.isLoopbackAddress()) {
return address;
}
}
}
}
}
catch (IOException ex) {
log.error("Cannot get host info", ex);
}
return InetAddress.getLocalHost();
}
}