Allow configuration of domainName and key for endpoint JMX export
This commit is contained in:
parent
fa1ff72fb1
commit
0a04b74379
|
|
@ -16,15 +16,19 @@
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure;
|
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.Endpoint;
|
||||||
import org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter;
|
import org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
|
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.jmx.export.MBeanExporter;
|
import org.springframework.jmx.export.MBeanExporter;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} to enable JMX export for
|
* {@link EnableAutoConfiguration Auto-configuration} to enable JMX export for
|
||||||
|
|
@ -38,10 +42,24 @@ import org.springframework.jmx.export.MBeanExporter;
|
||||||
@ConditionalOnExpression("${endpoints.jmx.enabled:true}")
|
@ConditionalOnExpression("${endpoints.jmx.enabled:true}")
|
||||||
class EndpointMBeanExportAutoConfiguration {
|
class EndpointMBeanExportAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
private RelaxedPropertyResolver environment;
|
||||||
public EndpointMBeanExporter endpointMBeanExporter() {
|
|
||||||
// TODO add configuration for domain name
|
@Autowired
|
||||||
return new EndpointMBeanExporter();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue