diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java index c9b4111d..e6f76fc7 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/DefaultServiceInstance.java @@ -123,32 +123,32 @@ public class DefaultServiceInstance implements ServiceInstance { @Override public Map getMetadata() { - return this.metadata; + return metadata; } @Override public String getInstanceId() { - return this.instanceId; + return instanceId; } @Override public String getServiceId() { - return this.serviceId; + return serviceId; } @Override public String getHost() { - return this.host; + return host; } @Override public int getPort() { - return this.port; + return port; } @Override public boolean isSecure() { - return this.secure; + return secure; } public void setInstanceId(String instanceId) { @@ -179,10 +179,10 @@ public class DefaultServiceInstance implements ServiceInstance { @Override public String toString() { - return "DefaultServiceInstance{" + "instanceId='" + this.instanceId + '\'' - + ", serviceId='" + this.serviceId + '\'' + ", host='" + this.host + '\'' - + ", port=" + this.port + ", secure=" + this.secure + ", metadata=" - + this.metadata + '}'; + return "DefaultServiceInstance{" + "instanceId='" + instanceId + '\'' + + ", serviceId='" + serviceId + '\'' + ", host='" + host + '\'' + + ", port=" + port + ", secure=" + secure + ", metadata=" + metadata + + '}'; } @Override @@ -194,17 +194,16 @@ public class DefaultServiceInstance implements ServiceInstance { return false; } DefaultServiceInstance that = (DefaultServiceInstance) o; - return this.port == that.port && this.secure == that.secure - && Objects.equals(this.instanceId, that.instanceId) - && Objects.equals(this.serviceId, that.serviceId) - && Objects.equals(this.host, that.host) - && Objects.equals(this.metadata, that.metadata); + return port == that.port && secure == that.secure + && Objects.equals(instanceId, that.instanceId) + && Objects.equals(serviceId, that.serviceId) + && Objects.equals(host, that.host) + && Objects.equals(metadata, that.metadata); } @Override public int hashCode() { - return Objects.hash(this.instanceId, this.serviceId, this.host, this.port, - this.secure, this.metadata); + return Objects.hash(instanceId, serviceId, host, port, secure, metadata); } } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientAutoConfiguration.java index c6a2b58c..1e877b78 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/SimpleDiscoveryClientAutoConfiguration.java @@ -66,9 +66,8 @@ public class SimpleDiscoveryClientAutoConfiguration public SimpleDiscoveryProperties simpleDiscoveryProperties( @Value("${spring.application.name:application}") String serviceId) { simple.getLocal().setServiceId(serviceId); - simple.getLocal().setHost(this.inet.findFirstNonLoopbackHostInfo().getHostname()); + simple.getLocal().setHost(inet.findFirstNonLoopbackHostInfo().getHostname()); simple.getLocal().setPort(findPort()); - return simple; } @@ -82,18 +81,18 @@ public class SimpleDiscoveryClientAutoConfiguration if (port > 0) { return port; } - if (this.server != null && this.server.getPort() != null - && this.server.getPort() > 0) { - return this.server.getPort(); + if (server != null && server.getPort() != null && server.getPort() > 0) { + return server.getPort(); } return 8080; } @Override public void onApplicationEvent(WebServerInitializedEvent webServerInitializedEvent) { - this.port = webServerInitializedEvent.getWebServer().getPort(); - if (this.port > 0) { - simple.getLocal().setPort(this.port); + port = webServerInitializedEvent.getWebServer().getPort(); + if (port > 0) { + simple.getLocal().setHost(inet.findFirstNonLoopbackHostInfo().getHostname()); + simple.getLocal().setPort(port); } } diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientAutoConfiguration.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientAutoConfiguration.java index 96d693dd..31efe366 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientAutoConfiguration.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/simple/reactive/SimpleReactiveDiscoveryClientAutoConfiguration.java @@ -95,6 +95,7 @@ public class SimpleReactiveDiscoveryClientAutoConfiguration public void onApplicationEvent(WebServerInitializedEvent webServerInitializedEvent) { port = webServerInitializedEvent.getWebServer().getPort(); if (port > 0) { + simple.getLocal().setHost(inet.findFirstNonLoopbackHostInfo().getHostname()); simple.getLocal().setPort(port); } }