Create InetUtils in default ConsulDiscoveryProperties constructor.

Fixes gh-683
This commit is contained in:
spencergibb
2021-01-11 12:25:25 -05:00
parent 8848d27867
commit 2be3632d8d
2 changed files with 4 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ 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.InetUtils.HostInfo;
import org.springframework.cloud.commons.util.InetUtilsProperties;
import org.springframework.core.style.ToStringCreator;
/**
@@ -207,11 +208,11 @@ public class ConsulDiscoveryProperties {
@SuppressWarnings("unused")
private ConsulDiscoveryProperties() {
this.managementTags.add(MANAGEMENT);
this(new InetUtils(new InetUtilsProperties()));
}
public ConsulDiscoveryProperties(InetUtils inetUtils) {
this();
this.managementTags.add(MANAGEMENT);
this.hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
this.ipAddress = this.hostInfo.getIpAddress();
this.hostname = this.hostInfo.getHostname();

View File

@@ -55,6 +55,7 @@ public class ConsulConfigServerBootstrapperTests {
BindHandlerBootstrapper bindHandlerBootstrapper = new BindHandlerBootstrapper();
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfig.class)
.properties("--server.port=0", "spring.cloud.config.discovery.enabled=true",
"spring.cloud.consul.discovery.hostname=myhost",
"spring.cloud.service-registry.auto-registration.enabled=false",
"spring.cloud.consul.host=localhost")
.addBootstrapper(bindHandlerBootstrapper)