Skip to content

Commit 3ea84f9

Browse files
artembilansnicoll
authored andcommitted
Fix relaxed binding of SI JMX config
Instead of using an expression for JMX-related properties, this commit properly honors relaxed binding. Closes gh-6184
1 parent 9abca48 commit 3ea84f9

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,30 @@
1616

1717
package org.springframework.boot.autoconfigure.integration;
1818

19+
import javax.management.MBeanServer;
20+
21+
import org.springframework.beans.BeansException;
22+
import org.springframework.beans.factory.BeanFactory;
23+
import org.springframework.beans.factory.BeanFactoryAware;
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.beans.factory.annotation.Qualifier;
1926
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2027
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2128
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2229
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2330
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
2431
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
32+
import org.springframework.boot.bind.RelaxedPropertyResolver;
33+
import org.springframework.context.EnvironmentAware;
34+
import org.springframework.context.annotation.Bean;
2535
import org.springframework.context.annotation.Configuration;
36+
import org.springframework.context.annotation.Primary;
37+
import org.springframework.core.env.Environment;
2638
import org.springframework.integration.config.EnableIntegration;
2739
import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport;
2840
import org.springframework.integration.monitor.IntegrationMBeanExporter;
41+
import org.springframework.integration.support.management.IntegrationManagementConfigurer;
42+
import org.springframework.util.StringUtils;
2943

3044
/**
3145
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
@@ -50,8 +64,49 @@ protected static class IntegrationConfiguration {
5064
@ConditionalOnClass(EnableIntegrationMBeanExport.class)
5165
@ConditionalOnMissingBean(value = IntegrationMBeanExporter.class, search = SearchStrategy.CURRENT)
5266
@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true)
53-
@EnableIntegrationMBeanExport(defaultDomain = "${spring.jmx.default-domain:}", server = "${spring.jmx.server:mbeanServer}")
54-
protected static class IntegrationJmxConfiguration {
67+
protected static class IntegrationJmxConfiguration implements EnvironmentAware, BeanFactoryAware {
68+
69+
private BeanFactory beanFactory;
70+
71+
private RelaxedPropertyResolver propertyResolver;
72+
73+
@Autowired(required = false)
74+
@Qualifier(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME)
75+
private IntegrationManagementConfigurer configurer;
76+
77+
@Override
78+
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
79+
this.beanFactory = beanFactory;
80+
}
81+
82+
@Override
83+
public void setEnvironment(Environment environment) {
84+
this.propertyResolver = new RelaxedPropertyResolver(environment, "spring.jmx.");
85+
}
86+
87+
@Bean
88+
@Primary
89+
public IntegrationMBeanExporter integrationMbeanExporter() {
90+
IntegrationMBeanExporter exporter = new IntegrationMBeanExporter();
91+
String defaultDomain = this.propertyResolver.getProperty("default-domain");
92+
if (StringUtils.hasLength(defaultDomain)) {
93+
exporter.setDefaultDomain(defaultDomain);
94+
}
95+
String server = this.propertyResolver.getProperty("server", "mbeanServer");
96+
if (StringUtils.hasLength(server)) {
97+
exporter.setServer(this.beanFactory.getBean(server, MBeanServer.class));
98+
}
99+
if (this.configurer != null) {
100+
if (this.configurer.getDefaultCountsEnabled() == null) {
101+
this.configurer.setDefaultCountsEnabled(true);
102+
}
103+
if (this.configurer.getDefaultStatsEnabled() == null) {
104+
this.configurer.setDefaultStatsEnabled(true);
105+
}
106+
}
107+
return exporter;
108+
}
109+
55110
}
56111

57112
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void disableJmxIntegration() {
9292

9393
@Test
9494
public void customizeJmxDomain() {
95-
load("spring.jmx.default-domain=org.foo");
95+
load("SPRING_JMX_DEFAULT_DOMAIN=org.foo");
9696
MBeanServer mBeanServer = this.context.getBean(MBeanServer.class);
9797
assertDomains(mBeanServer, true, "org.foo");
9898
assertDomains(mBeanServer, false, "org.springframework.integration",

0 commit comments

Comments
 (0)