Commit f41edfd4 by Dave Syer

Add conditional config guard for MBeanServer

parent b9350276
...@@ -21,6 +21,7 @@ import javax.management.MBeanServer; ...@@ -21,6 +21,7 @@ import javax.management.MBeanServer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
...@@ -56,7 +57,8 @@ import com.netflix.discovery.EurekaClientConfig; ...@@ -56,7 +57,8 @@ import com.netflix.discovery.EurekaClientConfig;
public class EurekaClientConfiguration implements public class EurekaClientConfiguration implements
ApplicationListener<ContextRefreshedEvent>, SmartLifecycle, Ordered { ApplicationListener<ContextRefreshedEvent>, SmartLifecycle, Ordered {
private static final Logger logger = LoggerFactory.getLogger(EurekaClientConfiguration.class); private static final Logger logger = LoggerFactory
.getLogger(EurekaClientConfiguration.class);
private boolean running; private boolean running;
...@@ -70,7 +72,8 @@ public class EurekaClientConfiguration implements ...@@ -70,7 +72,8 @@ public class EurekaClientConfiguration implements
@Override @Override
public void onApplicationEvent(ContextRefreshedEvent event) { public void onApplicationEvent(ContextRefreshedEvent event) {
logger.info("Registering application {} with eureka with status UP", instanceConfig.getAppname()); logger.info("Registering application {} with eureka with status UP",
instanceConfig.getAppname());
ApplicationInfoManager.getInstance().setInstanceStatus(InstanceStatus.UP); ApplicationInfoManager.getInstance().setInstanceStatus(InstanceStatus.UP);
} }
...@@ -117,15 +120,18 @@ public class EurekaClientConfiguration implements ...@@ -117,15 +120,18 @@ public class EurekaClientConfiguration implements
@Bean @Bean
@Lazy @Lazy
@Scope(proxyMode=ScopedProxyMode.TARGET_CLASS) @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public DiscoveryClient discoveryClient() { public DiscoveryClient discoveryClient() {
return DiscoveryManager.getInstance().getDiscoveryClient(); return DiscoveryManager.getInstance().getDiscoveryClient();
} }
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public EurekaHealthIndicator eurekaHealthIndicator(MBeanServer server, EurekaInstanceConfig config) { @ConditionalOnBean(MBeanServer.class)
return new EurekaHealthIndicator(discoveryClient(), new ServoMetricReader(server), config); public EurekaHealthIndicator eurekaHealthIndicator(MBeanServer server,
EurekaInstanceConfig config) {
return new EurekaHealthIndicator(discoveryClient(),
new ServoMetricReader(server), config);
} }
} }
...@@ -35,14 +35,15 @@ import com.netflix.servo.monitor.Monitors; ...@@ -35,14 +35,15 @@ import com.netflix.servo.monitor.Monitors;
* *
*/ */
@Configuration @Configuration
@ConditionalOnClass({Monitors.class,MetricReader.class}) @ConditionalOnClass({ Monitors.class, MetricReader.class })
@ConditionalOnBean({MBeanServer.class,MetricReader.class}) @ConditionalOnBean(MetricReader.class)
@AutoConfigureBefore(EndpointAutoConfiguration.class) @AutoConfigureBefore(EndpointAutoConfiguration.class)
@AutoConfigureAfter(MetricRepositoryAutoConfiguration.class) @AutoConfigureAfter(MetricRepositoryAutoConfiguration.class)
public class ServoMetricsAutoConfiguration { public class ServoMetricsAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnBean(MBeanServer.class)
public ServoPublicMetrics servoPublicMetrics(MetricReader reader, MBeanServer server) { public ServoPublicMetrics servoPublicMetrics(MetricReader reader, MBeanServer server) {
return new ServoPublicMetrics(reader, server); return new ServoPublicMetrics(reader, server);
} }
......
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