Update to use new InetUtils bean for nic discovery.
This commit is contained in:
@@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.consul.ConditionalOnConsulEnabled;
|
||||
import org.springframework.cloud.util.InetUtils;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -39,8 +40,8 @@ public class ConsulDiscoveryClientConfiguration {
|
||||
private ConsulClient consulClient;
|
||||
|
||||
@Bean
|
||||
public ConsulLifecycle consulLifecycle() {
|
||||
return new ConsulLifecycle(consulClient, lifecycleProperties(), consulDiscoveryProperties(), heartbeatProperties());
|
||||
public ConsulLifecycle consulLifecycle(ConsulDiscoveryProperties discoveryProperties) {
|
||||
return new ConsulLifecycle(consulClient, lifecycleProperties(), discoveryProperties, heartbeatProperties());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -60,17 +61,17 @@ public class ConsulDiscoveryClientConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConsulDiscoveryProperties consulDiscoveryProperties() {
|
||||
return new ConsulDiscoveryProperties();
|
||||
public ConsulDiscoveryProperties consulDiscoveryProperties(InetUtils inetUtils) {
|
||||
return new ConsulDiscoveryProperties(inetUtils);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConsulDiscoveryClient consulDiscoveryClient(ServerProperties serverProperties) {
|
||||
return new ConsulDiscoveryClient(consulClient, consulLifecycle(), consulDiscoveryProperties(), serverProperties);
|
||||
public ConsulDiscoveryClient consulDiscoveryClient(ServerProperties serverProperties, ConsulDiscoveryProperties discoveryProperties) {
|
||||
return new ConsulDiscoveryClient(consulClient, consulLifecycle(discoveryProperties), discoveryProperties, serverProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConsulCatalogWatch consulCatalogWatch() {
|
||||
return new ConsulCatalogWatch(consulDiscoveryProperties(), consulClient);
|
||||
public ConsulCatalogWatch consulCatalogWatch(ConsulDiscoveryProperties discoveryProperties) {
|
||||
return new ConsulCatalogWatch(discoveryProperties, consulClient);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import lombok.Setter;
|
||||
import lombok.extern.apachecommons.CommonsLog;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.util.InetUtils;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -43,7 +44,7 @@ public class ConsulDiscoveryProperties {
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
@Setter(AccessLevel.PRIVATE)
|
||||
private String[] hostInfo = initHostInfo();
|
||||
private InetUtils.HostInfo hostInfo;
|
||||
|
||||
private String aclToken;
|
||||
|
||||
@@ -59,9 +60,9 @@ public class ConsulDiscoveryProperties {
|
||||
|
||||
private String healthCheckInterval = "10s";
|
||||
|
||||
private String ipAddress = this.hostInfo[0];
|
||||
private String ipAddress;
|
||||
|
||||
private String hostname = hostInfo[1];
|
||||
private String hostname;
|
||||
|
||||
/**
|
||||
* Use ip address rather than hostname during registration
|
||||
@@ -78,15 +79,15 @@ public class ConsulDiscoveryProperties {
|
||||
|
||||
private String managementSuffix = MANAGEMENT;
|
||||
|
||||
private ConsulDiscoveryProperties() {}
|
||||
|
||||
public ConsulDiscoveryProperties(InetUtils inetUtils) {
|
||||
this.hostInfo = inetUtils.findFirstNonLoopbackHostInfo();
|
||||
this.ipAddress = this.hostInfo.getIpAddress();
|
||||
this.hostname = this.hostInfo.getHostname();
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return this.preferIpAddress ? this.ipAddress : this.hostname;
|
||||
}
|
||||
|
||||
private String[] initHostInfo() {
|
||||
String[] info = new String[2];
|
||||
InetAddress address = getFirstNonLoopbackAddress();
|
||||
info[0] = address.getHostAddress();
|
||||
info[1] = address.getHostName();
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user