Allow configuration of domainName and key for endpoint JMX export

This commit is contained in:
Christian Dupuis 2013-12-18 21:11:58 +01:00
parent fa1ff72fb1
commit 0a04b74379
1 changed files with 22 additions and 4 deletions

View File

@ -16,15 +16,19 @@
package org.springframework.boot.actuate.autoconfigure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.util.StringUtils;
/**
* {@link EnableAutoConfiguration Auto-configuration} to enable JMX export for
@ -38,10 +42,24 @@ import org.springframework.jmx.export.MBeanExporter;
@ConditionalOnExpression("${endpoints.jmx.enabled:true}")
class EndpointMBeanExportAutoConfiguration {
@Bean
public EndpointMBeanExporter endpointMBeanExporter() {
// TODO add configuration for domain name
return new EndpointMBeanExporter();
private RelaxedPropertyResolver environment;
@Autowired
public void setEnvironment(Environment environment) {
this.environment = new RelaxedPropertyResolver(environment);
}
@Bean
public EndpointMBeanExporter endpointMBeanExporter() {
EndpointMBeanExporter mbeanExporter = new EndpointMBeanExporter();
String domainName = this.environment.getProperty("endpoints.jmx.domain_name");
if (StringUtils.hasText(domainName)) {
mbeanExporter.setDomainName(domainName);
}
String key = this.environment.getProperty("endpoints.jmx.key");
if (StringUtils.hasText(key)) {
mbeanExporter.setKey(key);
}
return mbeanExporter;
}
}