Fix circular reference during object creation.

parent 799fbf43
......@@ -27,6 +27,7 @@ import java.net.URL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.health.Health;
......@@ -96,8 +97,6 @@ public class EurekaClientAutoConfiguration {
private static final Log log = LogFactory.getLog(EurekaClientAutoConfiguration.class);
private ConfigurableEnvironment env;
@Autowired(required = false)
private HealthCheckHandler healthCheckHandler;
public EurekaClientAutoConfiguration(ConfigurableEnvironment env) {
this.env = env;
......@@ -185,7 +184,7 @@ public class EurekaClientAutoConfiguration {
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient, CloudEurekaInstanceConfig instanceConfig, ApplicationInfoManager applicationInfoManager) {
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient, CloudEurekaInstanceConfig instanceConfig, ApplicationInfoManager applicationInfoManager, ObjectProvider<HealthCheckHandler> healthCheckHandler) {
return EurekaRegistration.builder(instanceConfig)
.with(applicationInfoManager)
.with(eurekaClient)
......
......@@ -27,6 +27,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.netflix.eureka.CloudEurekaClient;
......@@ -51,9 +52,9 @@ public class EurekaRegistration implements Registration, Closeable {
private final AtomicReference<CloudEurekaClient> cloudEurekaClient = new AtomicReference<>();
private final CloudEurekaInstanceConfig instanceConfig;
private final ApplicationInfoManager applicationInfoManager;
private HealthCheckHandler healthCheckHandler;
private ObjectProvider<HealthCheckHandler> healthCheckHandler;
private EurekaRegistration(CloudEurekaInstanceConfig instanceConfig, EurekaClient eurekaClient, ApplicationInfoManager applicationInfoManager, HealthCheckHandler healthCheckHandler) {
private EurekaRegistration(CloudEurekaInstanceConfig instanceConfig, EurekaClient eurekaClient, ApplicationInfoManager applicationInfoManager, ObjectProvider<HealthCheckHandler> healthCheckHandler) {
this.eurekaClient = eurekaClient;
this.instanceConfig = instanceConfig;
this.applicationInfoManager = applicationInfoManager;
......@@ -68,7 +69,7 @@ public class EurekaRegistration implements Registration, Closeable {
private final CloudEurekaInstanceConfig instanceConfig;
private ApplicationInfoManager applicationInfoManager;
private EurekaClient eurekaClient;
private HealthCheckHandler healthCheckHandler;
private ObjectProvider<HealthCheckHandler> healthCheckHandler;
private EurekaClientConfig clientConfig;
private ApplicationEventPublisher publisher;
......@@ -87,7 +88,7 @@ public class EurekaRegistration implements Registration, Closeable {
return this;
}
public Builder with(HealthCheckHandler healthCheckHandler) {
public Builder with(ObjectProvider<HealthCheckHandler> healthCheckHandler) {
this.healthCheckHandler = healthCheckHandler;
return this;
}
......@@ -177,11 +178,11 @@ public class EurekaRegistration implements Registration, Closeable {
return applicationInfoManager;
}
public HealthCheckHandler getHealthCheckHandler() {
public ObjectProvider<HealthCheckHandler> getHealthCheckHandler() {
return healthCheckHandler;
}
public void setHealthCheckHandler(HealthCheckHandler healthCheckHandler) {
public void setHealthCheckHandler(ObjectProvider<HealthCheckHandler> healthCheckHandler) {
this.healthCheckHandler = healthCheckHandler;
}
......
......@@ -45,9 +45,8 @@ public class EurekaServiceRegistry implements ServiceRegistry<EurekaRegistration
reg.getApplicationInfoManager()
.setInstanceStatus(reg.getInstanceConfig().getInitialStatus());
if (reg.getHealthCheckHandler() != null) {
reg.getEurekaClient().registerHealthCheck(reg.getHealthCheckHandler());
}
reg.getHealthCheckHandler().ifAvailable(healthCheckHandler ->
reg.getEurekaClient().registerHealthCheck(healthCheckHandler));
}
private void maybeInitializeClient(EurekaRegistration reg) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment