diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaClientConfiguration.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaClientConfiguration.java index 2f08dd92..734623fa 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaClientConfiguration.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaClientConfiguration.java @@ -27,6 +27,9 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.SmartLifecycle; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.core.Ordered; @@ -109,6 +112,8 @@ public class EurekaClientConfiguration implements } @Bean + @Lazy + @Scope(proxyMode=ScopedProxyMode.TARGET_CLASS) public DiscoveryClient discoveryClient() { return DiscoveryManager.getInstance().getDiscoveryClient(); } diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaInstanceConfigBean.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaInstanceConfigBean.java index 01a6ce98..43622b08 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaInstanceConfigBean.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaInstanceConfigBean.java @@ -66,7 +66,7 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig { private int leaseExpirationDurationInSeconds = 90; - @Value("${spring.application.name:unknown}") //TODO: why is .mydomain.net here? + @Value("${spring.application.name:unknown}") private String virtualHostName; private String secureVirtualHostName; @@ -99,6 +99,12 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig { private String namespace = "eureka"; private String hostname = hostInfo[1]; + + private boolean preferIpAddress = false; + + public String getHostname() { + return preferIpAddress ? ipAddress : hostname; + } @Override public boolean getSecurePortEnabled() { @@ -118,7 +124,7 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig { @Override public String getHostName(boolean refresh) { - return hostname; + return preferIpAddress ? ipAddress : hostname; } }