From cf0cff7cadaa42c2ba7e9b4b5d52898b758de087 Mon Sep 17 00:00:00 2001 From: lai hui <1353307710@qq.com> Date: Fri, 1 Jul 2022 16:30:59 +0800 Subject: [PATCH 1/8] support IPV6 --- .../cloud/nacos/NacosDiscoveryProperties.java | 247 +++++++++++++++++- 1 file changed, 238 insertions(+), 9 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index 0b0d27a90..698fb7e66 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -16,14 +16,15 @@ package com.alibaba.cloud.nacos; -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; +import java.io.Closeable; +import java.io.IOException; +import java.net.*; +import java.nio.ByteBuffer; +import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -34,6 +35,8 @@ import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.PreservedMetadataKeys; import com.alibaba.nacos.client.naming.utils.UtilAndComs; import com.alibaba.spring.util.PropertySourcesUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,6 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.commons.util.InetUtils; +import org.springframework.cloud.commons.util.InetUtilsProperties; import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; @@ -161,6 +165,11 @@ public class NacosDiscoveryProperties { */ private String networkInterface = ""; + /** + * choose IPV4 or IPV6,if you don't set it will choose IPV4 + */ + private String ipType = "IPV6" ; + /** * The port your want to register for your service instance, needn't to set it if the * auto detect port works well. @@ -213,6 +222,8 @@ public class NacosDiscoveryProperties { */ private boolean failFast = true; + private InetUtilsIPV6 inetUtilsIPV6 = new InetUtilsIPV6(); + @Autowired private InetUtils inetUtils; @@ -244,7 +255,17 @@ public class NacosDiscoveryProperties { if (StringUtils.isEmpty(ip)) { // traversing network interfaces if didn't specify a interface if (StringUtils.isEmpty(networkInterface)) { - ip = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); + if (ipType.equalsIgnoreCase("IPV4")){ + ip = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); + }else if (ipType.equalsIgnoreCase("IPV6")){ + ip = inetUtilsIPV6.findFirstNonLoopbackHostInfo().getIpAddress(); + int index = ip.indexOf('%'); + ip = index > 0 ? ip.substring(0, index) : ip; + ip = "["+ip+"]"; + }else { + throw new IllegalArgumentException( + "please checking the type of IP " + ipType); + } } else { NetworkInterface netInterface = NetworkInterface @@ -258,6 +279,7 @@ public class NacosDiscoveryProperties { while (inetAddress.hasMoreElements()) { InetAddress currentAddress = inetAddress.nextElement(); if (currentAddress instanceof Inet4Address + || currentAddress instanceof Inet6Address && !currentAddress.isLoopbackAddress()) { ip = currentAddress.getHostAddress(); break; @@ -279,6 +301,205 @@ public class NacosDiscoveryProperties { } } + class InetUtilsIPV6 implements Closeable { + private final ExecutorService executorService; + + private final Log log = LogFactory.getLog(com.alibaba.cloud.nacos.NacosDiscoveryProperties.InetUtilsIPV6.class); + + @Value("${spring.cloud.inetutils.default-hostname}") + private String defaultHostname = "localhost"; + + @Value("${spring.cloud.inetutils.default-ip-address}") + private String defaultIpAddress = "0:0:0:0:0:0:0:1"; + + @Value("${spring.cloud.inetutils.ignored-interfaces}") + private List ignoredInterfaces = new ArrayList(); + + @Value("${spring.util.timeout.sec:${SPRING_UTIL_TIMEOUT_SEC:1}}") + private int timeoutSeconds = 1; + + @Value("${spring.cloud.inetutils.use-only-site-local-interfaces}") + private boolean useOnlySiteLocalInterfaces = false; + + @Value("${spring.cloud.inetutils.preferred-networks}") + private List preferredNetworks = new ArrayList(); + + public InetUtilsIPV6() { + this.executorService = Executors.newSingleThreadExecutor((r) -> { + Thread thread = new Thread(r); + thread.setName("spring.cloud.alibaba.inetutilsIPV6"); + thread.setDaemon(true); + return thread; + }); + } + + public void close() { + this.executorService.shutdown(); + } + + public InetUtils.HostInfo findFirstNonLoopbackHostInfo() { + InetAddress address = this.findFirstNonLoopbackAddress(); + if (address != null) { + return this.convertAddress(address); + } else { + InetUtils.HostInfo hostInfo = new InetUtils.HostInfo(); + hostInfo.setHostname(defaultHostname); + hostInfo.setIpAddress(defaultIpAddress); + return hostInfo; + } + } + + public InetAddress findFirstNonLoopbackAddress() { + InetAddress result = null; + + try { + int lowest = 2147483647; + Enumeration nics = NetworkInterface.getNetworkInterfaces(); + + label61: + while(true) { + NetworkInterface ifc; + do { + while(true) { + do { + if (!nics.hasMoreElements()) { + break label61; + } + + ifc = (NetworkInterface)nics.nextElement(); + } while(!ifc.isUp()); + + this.log.trace("Testing interface: " + ifc.getDisplayName()); + if (ifc.getIndex() >= lowest && result != null) { + if (result != null) { + continue; + } + break; + } + + lowest = ifc.getIndex(); + break; + } + } while(this.ignoreInterface(ifc.getDisplayName())); + + Enumeration addrs = ifc.getInetAddresses(); + + while(addrs.hasMoreElements()) { + InetAddress address = (InetAddress)addrs.nextElement(); + if (address instanceof Inet6Address && !address.isLoopbackAddress() && this.isPreferredAddress(address)) { + this.log.trace("Found non-loopback interface: " + ifc.getDisplayName()); + result = address; + } + } + } + } catch (IOException var8) { + this.log.error("Cannot get first non-loopback address", var8); + } + + if (result != null) { + return result; + } else { + try { + return InetAddress.getLocalHost(); + } catch (UnknownHostException var7) { + this.log.warn("Unable to retrieve localhost"); + return null; + } + } + } + + boolean isPreferredAddress(InetAddress address) { + if (this.isUseOnlySiteLocalInterfaces()) { + boolean siteLocalAddress = address.isSiteLocalAddress(); + if (!siteLocalAddress) { + this.log.trace("Ignoring address: " + address.getHostAddress()); + } + + return siteLocalAddress; + } else { + List preferredNetworks = this.getPreferredNetworks(); + if (preferredNetworks.isEmpty()) { + return true; + } else { + Iterator var3 = preferredNetworks.iterator(); + + String regex; + String hostAddress; + do { + if (!var3.hasNext()) { + this.log.trace("Ignoring address: " + address.getHostAddress()); + return false; + } + + regex = (String)var3.next(); + hostAddress = address.getHostAddress(); + } while(!hostAddress.matches(regex) && !hostAddress.startsWith(regex)); + + return true; + } + } + } + + boolean ignoreInterface(String interfaceName) { + Iterator var2 = this.getIgnoredInterfaces().iterator(); + + String regex; + do { + if (!var2.hasNext()) { + return false; + } + + regex = (String)var2.next(); + } while(!interfaceName.matches(regex)); + + this.log.trace("Ignoring interface: " + interfaceName); + return true; + } + + public InetUtils.HostInfo convertAddress(final InetAddress address) { + InetUtils.HostInfo hostInfo = new InetUtils.HostInfo(); + ExecutorService var10000 = this.executorService; + address.getClass(); + Future result = var10000.submit(address::getHostName); + + String hostname; + try { + hostname = (String)result.get((long)this.getTimeoutSeconds(), TimeUnit.SECONDS); + } catch (Exception var6) { + this.log.info("Cannot determine local hostname"); + hostname = "localhost"; + } + + hostInfo.setHostname(hostname); + hostInfo.setIpAddress(address.getHostAddress()); + return hostInfo; + } + + public String getDefaultHostname() { + return this.defaultHostname; + } + + public String getDefaultIpAddress() { + return this.defaultIpAddress; + } + + public int getTimeoutSeconds() { + return this.timeoutSeconds; + } + + public List getIgnoredInterfaces() { + return this.ignoredInterfaces; + } + + public boolean isUseOnlySiteLocalInterfaces() { + return this.useOnlySiteLocalInterfaces; + } + + public List getPreferredNetworks() { + return this.preferredNetworks; + } + } + /** * recommend to use {@link NacosServiceManager#getNamingService(Properties)}. * @return NamingService @@ -372,6 +593,14 @@ public class NacosDiscoveryProperties { this.port = port; } + public String getIpType() { + return ipType; + } + + public void setIpType(String ipType) { + this.ipType = ipType; + } + public boolean isSecure() { return secure; } From 9960b2521c5ac54033f97324545835530a4d1585 Mon Sep 17 00:00:00 2001 From: lai hui <1353307710@qq.com> Date: Fri, 1 Jul 2022 16:48:03 +0800 Subject: [PATCH 2/8] fix some error --- .../java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index 698fb7e66..98428e3e6 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -168,7 +168,7 @@ public class NacosDiscoveryProperties { /** * choose IPV4 or IPV6,if you don't set it will choose IPV4 */ - private String ipType = "IPV6" ; + private String ipType = "IPV4" ; /** * The port your want to register for your service instance, needn't to set it if the From 205fe2bbddd367881b7bc10501c2390495d742d8 Mon Sep 17 00:00:00 2001 From: lai hui <1353307710@qq.com> Date: Sat, 2 Jul 2022 16:42:34 +0800 Subject: [PATCH 3/8] fix some error --- .../cloud/nacos/NacosDiscoveryProperties.java | 221 +----------------- .../cloud/nacos/intetuntil/InetIPUtils.java | 148 ++++++++++++ .../intetuntil/UtilIPAutoConfiguration.java | 19 ++ .../main/resources/META-INF/spring.factories | 3 +- 4 files changed, 178 insertions(+), 213 deletions(-) create mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java create mode 100644 spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPAutoConfiguration.java diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index 98428e3e6..f4486451b 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -16,27 +16,19 @@ package com.alibaba.cloud.nacos; -import java.io.Closeable; -import java.io.IOException; import java.net.*; -import java.nio.ByteBuffer; import java.util.*; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.PostConstruct; import com.alibaba.cloud.nacos.event.NacosDiscoveryInfoChangedEvent; +import com.alibaba.cloud.nacos.intetuntil.InetIPUtils; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.PreservedMetadataKeys; import com.alibaba.nacos.client.naming.utils.UtilAndComs; import com.alibaba.spring.util.PropertySourcesUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +36,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.commons.util.InetUtils; -import org.springframework.cloud.commons.util.InetUtilsProperties; import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; @@ -168,7 +159,7 @@ public class NacosDiscoveryProperties { /** * choose IPV4 or IPV6,if you don't set it will choose IPV4 */ - private String ipType = "IPV4" ; + private String ipType = "IPv4" ; /** * The port your want to register for your service instance, needn't to set it if the @@ -222,7 +213,8 @@ public class NacosDiscoveryProperties { */ private boolean failFast = true; - private InetUtilsIPV6 inetUtilsIPV6 = new InetUtilsIPV6(); + @Autowired + private InetIPUtils inetIPUtils; @Autowired private InetUtils inetUtils; @@ -258,7 +250,7 @@ public class NacosDiscoveryProperties { if (ipType.equalsIgnoreCase("IPV4")){ ip = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); }else if (ipType.equalsIgnoreCase("IPV6")){ - ip = inetUtilsIPV6.findFirstNonLoopbackHostInfo().getIpAddress(); + ip = inetIPUtils.findFirstNonLoopbackHostInfo().getIpAddress(); int index = ip.indexOf('%'); ip = index > 0 ? ip.substring(0, index) : ip; ip = "["+ip+"]"; @@ -301,205 +293,6 @@ public class NacosDiscoveryProperties { } } - class InetUtilsIPV6 implements Closeable { - private final ExecutorService executorService; - - private final Log log = LogFactory.getLog(com.alibaba.cloud.nacos.NacosDiscoveryProperties.InetUtilsIPV6.class); - - @Value("${spring.cloud.inetutils.default-hostname}") - private String defaultHostname = "localhost"; - - @Value("${spring.cloud.inetutils.default-ip-address}") - private String defaultIpAddress = "0:0:0:0:0:0:0:1"; - - @Value("${spring.cloud.inetutils.ignored-interfaces}") - private List ignoredInterfaces = new ArrayList(); - - @Value("${spring.util.timeout.sec:${SPRING_UTIL_TIMEOUT_SEC:1}}") - private int timeoutSeconds = 1; - - @Value("${spring.cloud.inetutils.use-only-site-local-interfaces}") - private boolean useOnlySiteLocalInterfaces = false; - - @Value("${spring.cloud.inetutils.preferred-networks}") - private List preferredNetworks = new ArrayList(); - - public InetUtilsIPV6() { - this.executorService = Executors.newSingleThreadExecutor((r) -> { - Thread thread = new Thread(r); - thread.setName("spring.cloud.alibaba.inetutilsIPV6"); - thread.setDaemon(true); - return thread; - }); - } - - public void close() { - this.executorService.shutdown(); - } - - public InetUtils.HostInfo findFirstNonLoopbackHostInfo() { - InetAddress address = this.findFirstNonLoopbackAddress(); - if (address != null) { - return this.convertAddress(address); - } else { - InetUtils.HostInfo hostInfo = new InetUtils.HostInfo(); - hostInfo.setHostname(defaultHostname); - hostInfo.setIpAddress(defaultIpAddress); - return hostInfo; - } - } - - public InetAddress findFirstNonLoopbackAddress() { - InetAddress result = null; - - try { - int lowest = 2147483647; - Enumeration nics = NetworkInterface.getNetworkInterfaces(); - - label61: - while(true) { - NetworkInterface ifc; - do { - while(true) { - do { - if (!nics.hasMoreElements()) { - break label61; - } - - ifc = (NetworkInterface)nics.nextElement(); - } while(!ifc.isUp()); - - this.log.trace("Testing interface: " + ifc.getDisplayName()); - if (ifc.getIndex() >= lowest && result != null) { - if (result != null) { - continue; - } - break; - } - - lowest = ifc.getIndex(); - break; - } - } while(this.ignoreInterface(ifc.getDisplayName())); - - Enumeration addrs = ifc.getInetAddresses(); - - while(addrs.hasMoreElements()) { - InetAddress address = (InetAddress)addrs.nextElement(); - if (address instanceof Inet6Address && !address.isLoopbackAddress() && this.isPreferredAddress(address)) { - this.log.trace("Found non-loopback interface: " + ifc.getDisplayName()); - result = address; - } - } - } - } catch (IOException var8) { - this.log.error("Cannot get first non-loopback address", var8); - } - - if (result != null) { - return result; - } else { - try { - return InetAddress.getLocalHost(); - } catch (UnknownHostException var7) { - this.log.warn("Unable to retrieve localhost"); - return null; - } - } - } - - boolean isPreferredAddress(InetAddress address) { - if (this.isUseOnlySiteLocalInterfaces()) { - boolean siteLocalAddress = address.isSiteLocalAddress(); - if (!siteLocalAddress) { - this.log.trace("Ignoring address: " + address.getHostAddress()); - } - - return siteLocalAddress; - } else { - List preferredNetworks = this.getPreferredNetworks(); - if (preferredNetworks.isEmpty()) { - return true; - } else { - Iterator var3 = preferredNetworks.iterator(); - - String regex; - String hostAddress; - do { - if (!var3.hasNext()) { - this.log.trace("Ignoring address: " + address.getHostAddress()); - return false; - } - - regex = (String)var3.next(); - hostAddress = address.getHostAddress(); - } while(!hostAddress.matches(regex) && !hostAddress.startsWith(regex)); - - return true; - } - } - } - - boolean ignoreInterface(String interfaceName) { - Iterator var2 = this.getIgnoredInterfaces().iterator(); - - String regex; - do { - if (!var2.hasNext()) { - return false; - } - - regex = (String)var2.next(); - } while(!interfaceName.matches(regex)); - - this.log.trace("Ignoring interface: " + interfaceName); - return true; - } - - public InetUtils.HostInfo convertAddress(final InetAddress address) { - InetUtils.HostInfo hostInfo = new InetUtils.HostInfo(); - ExecutorService var10000 = this.executorService; - address.getClass(); - Future result = var10000.submit(address::getHostName); - - String hostname; - try { - hostname = (String)result.get((long)this.getTimeoutSeconds(), TimeUnit.SECONDS); - } catch (Exception var6) { - this.log.info("Cannot determine local hostname"); - hostname = "localhost"; - } - - hostInfo.setHostname(hostname); - hostInfo.setIpAddress(address.getHostAddress()); - return hostInfo; - } - - public String getDefaultHostname() { - return this.defaultHostname; - } - - public String getDefaultIpAddress() { - return this.defaultIpAddress; - } - - public int getTimeoutSeconds() { - return this.timeoutSeconds; - } - - public List getIgnoredInterfaces() { - return this.ignoredInterfaces; - } - - public boolean isUseOnlySiteLocalInterfaces() { - return this.useOnlySiteLocalInterfaces; - } - - public List getPreferredNetworks() { - return this.preferredNetworks; - } - } - /** * recommend to use {@link NacosServiceManager#getNamingService(Properties)}. * @return NamingService @@ -533,6 +326,10 @@ public class NacosDiscoveryProperties { this.logName = logName; } + public void setInetIPUtils(InetIPUtils inetIPUtils){ + this.inetIPUtils = inetIPUtils; + } + public void setInetUtils(InetUtils inetUtils) { this.inetUtils = inetUtils; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java new file mode 100644 index 000000000..712d41eca --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java @@ -0,0 +1,148 @@ +package com.alibaba.cloud.nacos.intetuntil; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.cloud.commons.util.InetUtils; +import org.springframework.cloud.commons.util.InetUtilsProperties; + +import java.io.Closeable; +import java.io.IOException; +import java.net.*; +import java.util.Enumeration; +import java.util.List; +import java.util.concurrent.*; + +public class InetIPUtils implements Closeable { + private final ExecutorService executorService; + + private final Log log = LogFactory.getLog(InetIPUtils.class); + + private final InetUtilsProperties properties; + + public InetIPUtils(final InetUtilsProperties properties) { + this.properties = properties; + this.executorService = Executors.newSingleThreadExecutor((r) -> { + Thread thread = new Thread(r); + thread.setName("spring.cloud.alibaba.inetutilsIPV6"); + thread.setDaemon(true); + return thread; + }); + } + + public void close() { + this.executorService.shutdown(); + } + + public InetUtils.HostInfo findFirstNonLoopbackHostInfo() { + InetAddress address = this.findFirstNonLoopbackAddress(); + if (address != null) { + return this.convertAddress(address); + } else { + InetUtils.HostInfo hostInfo = new InetUtils.HostInfo(); + this.properties.setDefaultIpAddress("0:0:0:0:0:0:0:1"); + hostInfo.setHostname(this.properties.getDefaultHostname()); + hostInfo.setIpAddress(this.properties.getDefaultIpAddress()); + return hostInfo; + } + } + + public InetAddress findFirstNonLoopbackAddress() { + InetAddress address = null; + + try { + int lowest = Integer.MAX_VALUE; + for (Enumeration nics = NetworkInterface.getNetworkInterfaces(); + nics.hasMoreElements();) { + NetworkInterface ifc = nics.nextElement(); + if (ifc.isUp()) { + log.trace("Testing interface:" + ifc.getDisplayName()); + if (ifc.getIndex() < lowest || address == null) { + lowest = ifc.getIndex(); + } + else if (address != null) { + continue; + } + + if (!ignoreInterface(ifc.getDisplayName())) { + for (Enumeration addrs = ifc + .getInetAddresses(); addrs.hasMoreElements();) { + InetAddress inetAddress = addrs.nextElement(); + if (inetAddress instanceof Inet6Address + && !inetAddress.isLoopbackAddress() + && isPreferredAddress(inetAddress)) { + this.log.trace("Found non-loopback interface: " + + ifc.getDisplayName()); + address = inetAddress; + } + } + } + } + } + } + catch (IOException e) { + log.error("Cannot get first non-loopback address", e); + } + + if (address != null) { + return address; + } + + try { + return InetAddress.getLocalHost(); + } + catch (UnknownHostException e) { + log.warn("Unable to retrieve localhost"); + } + + return null; + } + + boolean isPreferredAddress(InetAddress address) { + if (this.properties.isUseOnlySiteLocalInterfaces()) { + final boolean siteLocalAddress = address.isSiteLocalAddress(); + if (!siteLocalAddress) { + log.trace("Ignoring address"+address.getHostAddress()); + } + return siteLocalAddress; + } + final List preferredNetworks = this.properties.getPreferredNetworks(); + if (preferredNetworks.isEmpty()) { + return true; + } + for (String regex : preferredNetworks) { + final String hostAddress = address.getHostAddress(); + if (hostAddress.matches(regex) || hostAddress.startsWith(regex)) { + return true; + } + } + log.trace("Ignoring address: " + address.getHostAddress()); + return false; + } + + boolean ignoreInterface(String interfaceName) { + for (String regex : this.properties.getIgnoredInterfaces()) { + if (interfaceName.matches(regex)) { + log.trace("Ignoring interface: " + interfaceName); + return true; + } + } + return false; + } + + public InetUtils.HostInfo convertAddress(final InetAddress address) { + InetUtils.HostInfo hostInfo = new InetUtils.HostInfo(); + Future result = this.executorService.submit(address::getHostName); + + String hostname; + try { + hostname = result.get(this.properties.getTimeoutSeconds(), TimeUnit.SECONDS); + } + catch (Exception e) { + log.info("Cannot determine local hostname"); + hostname = "localhost"; + } + hostInfo.setHostname(hostname); + hostInfo.setIpAddress(address.getHostAddress()); + return hostInfo; + } +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPAutoConfiguration.java new file mode 100644 index 000000000..306d442f7 --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPAutoConfiguration.java @@ -0,0 +1,19 @@ +package com.alibaba.cloud.nacos.intetuntil; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.cloud.commons.util.InetUtilsProperties; +import org.springframework.context.annotation.Bean; + +@EnableAutoConfiguration +public class UtilIPAutoConfiguration{ + public UtilIPAutoConfiguration() { + } + + @Bean + @ConditionalOnMissingBean + public InetIPUtils inetUtils(InetUtilsProperties properties) { + return new InetIPUtils(properties); + } +} + diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories index dad08529a..c83e7ea0c 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories @@ -6,7 +6,8 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.alibaba.cloud.nacos.discovery.NacosDiscoveryClientConfiguration,\ com.alibaba.cloud.nacos.discovery.reactive.NacosReactiveDiscoveryClientConfiguration,\ com.alibaba.cloud.nacos.discovery.configclient.NacosConfigServerAutoConfiguration,\ - com.alibaba.cloud.nacos.NacosServiceAutoConfiguration + com.alibaba.cloud.nacos.NacosServiceAutoConfiguration,\ + com.alibaba.cloud.nacos.intetuntil.InetIPUtils org.springframework.cloud.bootstrap.BootstrapConfiguration=\ com.alibaba.cloud.nacos.discovery.configclient.NacosDiscoveryClientConfigServiceBootstrapConfiguration org.springframework.context.ApplicationListener=\ From 0e423295518a1593dc1182d9303451d14a40cbec Mon Sep 17 00:00:00 2001 From: lai hui <1353307710@qq.com> Date: Sat, 2 Jul 2022 21:19:56 +0800 Subject: [PATCH 4/8] fix some question --- .../com/alibaba/cloud/nacos/NacosDiscoveryProperties.java | 4 ++-- .../java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index f4486451b..b44aa0482 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -247,9 +247,9 @@ public class NacosDiscoveryProperties { if (StringUtils.isEmpty(ip)) { // traversing network interfaces if didn't specify a interface if (StringUtils.isEmpty(networkInterface)) { - if (ipType.equalsIgnoreCase("IPV4")){ + if (ipType.equalsIgnoreCase("IPv4")){ ip = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); - }else if (ipType.equalsIgnoreCase("IPV6")){ + }else if (ipType.equalsIgnoreCase("IPv6")){ ip = inetIPUtils.findFirstNonLoopbackHostInfo().getIpAddress(); int index = ip.indexOf('%'); ip = index > 0 ? ip.substring(0, index) : ip; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java index 712d41eca..f0402710d 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java @@ -70,7 +70,7 @@ public class InetIPUtils implements Closeable { if (inetAddress instanceof Inet6Address && !inetAddress.isLoopbackAddress() && isPreferredAddress(inetAddress)) { - this.log.trace("Found non-loopback interface: " + log.trace("Found non-loopback interface: " + ifc.getDisplayName()); address = inetAddress; } From 0c554d5e726a9f5175d3e2f9c1a2e7ff6cc51668 Mon Sep 17 00:00:00 2001 From: lai hui <1353307710@qq.com> Date: Tue, 5 Jul 2022 21:08:20 +0800 Subject: [PATCH 5/8] fix name --- .../cloud/nacos/NacosDiscoveryProperties.java | 6 ++--- .../{InetIPUtils.java => InetIPv6Utils.java} | 22 +++++++++++++------ ...on.java => UtilIPv6AutoConfiguration.java} | 8 +++---- .../main/resources/META-INF/spring.factories | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/{InetIPUtils.java => InetIPv6Utils.java} (89%) rename spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/{UtilIPAutoConfiguration.java => UtilIPv6AutoConfiguration.java} (66%) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index b44aa0482..d7a05ecac 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -24,7 +24,7 @@ import java.util.regex.Pattern; import javax.annotation.PostConstruct; import com.alibaba.cloud.nacos.event.NacosDiscoveryInfoChangedEvent; -import com.alibaba.cloud.nacos.intetuntil.InetIPUtils; +import com.alibaba.cloud.nacos.intetuntil.InetIPv6Utils; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.PreservedMetadataKeys; import com.alibaba.nacos.client.naming.utils.UtilAndComs; @@ -214,7 +214,7 @@ public class NacosDiscoveryProperties { private boolean failFast = true; @Autowired - private InetIPUtils inetIPUtils; + private InetIPv6Utils inetIPUtils; @Autowired private InetUtils inetUtils; @@ -326,7 +326,7 @@ public class NacosDiscoveryProperties { this.logName = logName; } - public void setInetIPUtils(InetIPUtils inetIPUtils){ + public void setInetIPUtils(InetIPv6Utils inetIPUtils){ this.inetIPUtils = inetIPUtils; } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPv6Utils.java similarity index 89% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPv6Utils.java index f0402710d..ef6c888c9 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPUtils.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPv6Utils.java @@ -7,19 +7,27 @@ import org.springframework.cloud.commons.util.InetUtilsProperties; import java.io.Closeable; import java.io.IOException; -import java.net.*; + +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.UnknownHostException; import java.util.Enumeration; import java.util.List; -import java.util.concurrent.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + -public class InetIPUtils implements Closeable { +public class InetIPv6Utils implements Closeable { private final ExecutorService executorService; - private final Log log = LogFactory.getLog(InetIPUtils.class); + private final Log log = LogFactory.getLog(InetIPv6Utils.class); private final InetUtilsProperties properties; - public InetIPUtils(final InetUtilsProperties properties) { + public InetIPv6Utils(final InetUtilsProperties properties) { this.properties = properties; this.executorService = Executors.newSingleThreadExecutor((r) -> { Thread thread = new Thread(r); @@ -34,7 +42,7 @@ public class InetIPUtils implements Closeable { } public InetUtils.HostInfo findFirstNonLoopbackHostInfo() { - InetAddress address = this.findFirstNonLoopbackAddress(); + InetAddress address = this.findFirstNonLoopbackIPv6Address(); if (address != null) { return this.convertAddress(address); } else { @@ -46,7 +54,7 @@ public class InetIPUtils implements Closeable { } } - public InetAddress findFirstNonLoopbackAddress() { + public InetAddress findFirstNonLoopbackIPv6Address() { InetAddress address = null; try { diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPAutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java similarity index 66% rename from spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPAutoConfiguration.java rename to spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java index 306d442f7..2d2a976c7 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPAutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java @@ -6,14 +6,14 @@ import org.springframework.cloud.commons.util.InetUtilsProperties; import org.springframework.context.annotation.Bean; @EnableAutoConfiguration -public class UtilIPAutoConfiguration{ - public UtilIPAutoConfiguration() { +public class UtilIPv6AutoConfiguration { + public UtilIPv6AutoConfiguration() { } @Bean @ConditionalOnMissingBean - public InetIPUtils inetUtils(InetUtilsProperties properties) { - return new InetIPUtils(properties); + public InetIPv6Utils inetUtils(InetUtilsProperties properties) { + return new InetIPv6Utils(properties); } } diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories index c83e7ea0c..92f91f592 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/resources/META-INF/spring.factories @@ -7,7 +7,7 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.alibaba.cloud.nacos.discovery.reactive.NacosReactiveDiscoveryClientConfiguration,\ com.alibaba.cloud.nacos.discovery.configclient.NacosConfigServerAutoConfiguration,\ com.alibaba.cloud.nacos.NacosServiceAutoConfiguration,\ - com.alibaba.cloud.nacos.intetuntil.InetIPUtils + com.alibaba.cloud.nacos.intetuntil.InetIPv6Utils org.springframework.cloud.bootstrap.BootstrapConfiguration=\ com.alibaba.cloud.nacos.discovery.configclient.NacosDiscoveryClientConfigServiceBootstrapConfiguration org.springframework.context.ApplicationListener=\ From ee36dfe18f49e802e74d6eaf9d9e8fe7148cfb7e Mon Sep 17 00:00:00 2001 From: lai hui <1353307710@qq.com> Date: Wed, 6 Jul 2022 22:30:53 +0800 Subject: [PATCH 6/8] fix some question --- .../nacos/intetuntil/UtilIPv6AutoConfiguration.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java index 2d2a976c7..14f0c30be 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java @@ -1,11 +1,16 @@ package com.alibaba.cloud.nacos.intetuntil; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; + import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; import org.springframework.cloud.commons.util.InetUtilsProperties; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; -@EnableAutoConfiguration +@Configuration(proxyBeanMethods = false) +@ConditionalOnDiscoveryEnabled +@ConditionalOnNacosDiscoveryEnabled public class UtilIPv6AutoConfiguration { public UtilIPv6AutoConfiguration() { } From b51607fcc24a29e55d1b2152b9719e238279ca41 Mon Sep 17 00:00:00 2001 From: lai hui <1353307710@qq.com> Date: Thu, 7 Jul 2022 16:04:20 +0800 Subject: [PATCH 7/8] fix import --- .../cloud/nacos/NacosDiscoveryProperties.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index d7a05ecac..4de879a4d 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -16,8 +16,16 @@ package com.alibaba.cloud.nacos; -import java.net.*; -import java.util.*; +import java.net.Inet4Address; + +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; From 2735e0329c248bafc97f789ad79e47640e10ccc1 Mon Sep 17 00:00:00 2001 From: lai hui <1353307710@qq.com> Date: Thu, 7 Jul 2022 18:53:39 +0800 Subject: [PATCH 8/8] add info --- .../com/alibaba/cloud/nacos/NacosDiscoveryProperties.java | 1 + .../com/alibaba/cloud/nacos/intetuntil/InetIPv6Utils.java | 4 +++- .../cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java index 4de879a4d..8bb7e3d2b 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/NacosDiscoveryProperties.java @@ -63,6 +63,7 @@ import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME; /** * @author dungu.zpf * @author xiaojing + * @author HH * @author Mercy * @author lyuzb * @author eshun diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPv6Utils.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPv6Utils.java index ef6c888c9..3a596d7e2 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPv6Utils.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/InetIPv6Utils.java @@ -19,7 +19,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; - +/** + * @author HH + */ public class InetIPv6Utils implements Closeable { private final ExecutorService executorService; diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java index 14f0c30be..f7588ec9e 100644 --- a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-nacos-discovery/src/main/java/com/alibaba/cloud/nacos/intetuntil/UtilIPv6AutoConfiguration.java @@ -8,6 +8,10 @@ import org.springframework.cloud.commons.util.InetUtilsProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; + +/** + * @author HH + */ @Configuration(proxyBeanMethods = false) @ConditionalOnDiscoveryEnabled @ConditionalOnNacosDiscoveryEnabled