Commit f41edfd4 by Dave Syer

Add conditional config guard for MBeanServer

parent b9350276
......@@ -21,6 +21,7 @@ import javax.management.MBeanServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
......@@ -56,7 +57,8 @@ import com.netflix.discovery.EurekaClientConfig;
public class EurekaClientConfiguration implements
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;
......@@ -70,7 +72,8 @@ public class EurekaClientConfiguration implements
@Override
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);
}
......@@ -117,15 +120,18 @@ public class EurekaClientConfiguration implements
@Bean
@Lazy
@Scope(proxyMode=ScopedProxyMode.TARGET_CLASS)
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public DiscoveryClient discoveryClient() {
return DiscoveryManager.getInstance().getDiscoveryClient();
}
@Bean
@ConditionalOnMissingBean
public EurekaHealthIndicator eurekaHealthIndicator(MBeanServer server, EurekaInstanceConfig config) {
return new EurekaHealthIndicator(discoveryClient(), new ServoMetricReader(server), config);
@ConditionalOnBean(MBeanServer.class)
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;
*
*/
@Configuration
@ConditionalOnClass({Monitors.class,MetricReader.class})
@ConditionalOnBean({MBeanServer.class,MetricReader.class})
@ConditionalOnClass({ Monitors.class, MetricReader.class })
@ConditionalOnBean(MetricReader.class)
@AutoConfigureBefore(EndpointAutoConfiguration.class)
@AutoConfigureAfter(MetricRepositoryAutoConfiguration.class)
public class ServoMetricsAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(MBeanServer.class)
public ServoPublicMetrics servoPublicMetrics(MetricReader reader, MBeanServer 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