Commit 06ffcdd3 authored by Christian Dupuis's avatar Christian Dupuis

Change configuration to use ConfigurationProperties instead of direct access...

Change configuration to use ConfigurationProperties instead of direct access to environment for MBean export
parent 1531329d
...@@ -19,15 +19,16 @@ package org.springframework.boot.actuate.autoconfigure; ...@@ -19,15 +19,16 @@ package org.springframework.boot.actuate.autoconfigure;
import java.util.Properties; import java.util.Properties;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.EndpointMBeanExportAutoConfiguration.EndpointMBeanExportProperties;
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.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
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.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
...@@ -39,39 +40,60 @@ import org.springframework.util.StringUtils; ...@@ -39,39 +40,60 @@ import org.springframework.util.StringUtils;
@Configuration @Configuration
@AutoConfigureAfter({ EndpointAutoConfiguration.class }) @AutoConfigureAfter({ EndpointAutoConfiguration.class })
@ConditionalOnExpression("${endpoints.jmx.enabled:true}") @ConditionalOnExpression("${endpoints.jmx.enabled:true}")
@EnableConfigurationProperties(EndpointMBeanExportProperties.class)
class EndpointMBeanExportAutoConfiguration { class EndpointMBeanExportAutoConfiguration {
private RelaxedPropertyResolver environment;
@Autowired @Autowired
public void setEnvironment(Environment environment) { EndpointMBeanExportProperties properties = new EndpointMBeanExportProperties();
this.environment = new RelaxedPropertyResolver(environment);
}
@Bean @Bean
public EndpointMBeanExporter endpointMBeanExporter() { public EndpointMBeanExporter endpointMBeanExporter() {
EndpointMBeanExporter mbeanExporter = new EndpointMBeanExporter(); EndpointMBeanExporter mbeanExporter = new EndpointMBeanExporter();
String domain = this.environment.getProperty("endpoints.jmx.domain"); String domain = this.properties.getDomain();
if (StringUtils.hasText(domain)) { if (StringUtils.hasText(domain)) {
mbeanExporter.setDomain(domain); mbeanExporter.setDomain(domain);
} }
Boolean ensureUnique = this.environment.getProperty("endpoints.jmx.unique_names", mbeanExporter.setEnsureUniqueRuntimeObjectNames(this.properties.getUniqueNames());
Boolean.class, Boolean.FALSE); mbeanExporter.setObjectNameStaticProperties(this.properties.getStaticNames());
mbeanExporter.setEnsureUniqueRuntimeObjectNames(ensureUnique);
mbeanExporter.setObjectNameStaticProperties(getObjectNameStaticProperties());
return mbeanExporter; return mbeanExporter;
} }
private Properties getObjectNameStaticProperties() { @ConfigurationProperties(name = "endpoints.jmx")
String staticNames = this.environment.getProperty("endpoints.jmx.static_names"); public static class EndpointMBeanExportProperties {
if (StringUtils.hasText(staticNames)) {
return StringUtils.splitArrayElementsIntoProperties( private String domain;
StringUtils.commaDelimitedListToStringArray(staticNames), "=");
private boolean uniqueNames = false;
private Properties staticNames = new Properties();
public String getDomain() {
return this.domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public boolean getUniqueNames() {
return this.uniqueNames;
}
public void setUniqueNames(boolean uniqueNames) {
this.uniqueNames = uniqueNames;
}
public Properties getStaticNames() {
return this.staticNames;
}
public void setStaticNames(String[] staticNames) {
this.staticNames = StringUtils.splitArrayElementsIntoProperties(staticNames,
"=");
} }
return new Properties();
} }
} }
\ No newline at end of file
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