Add global support for JMX unique names
See gh-13990
This commit is contained in:
@@ -49,6 +49,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
* @author Madhura Bhave
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ MBeanExporter.class })
|
||||
@@ -93,6 +94,11 @@ public class JmxAutoConfiguration implements EnvironmentAware, BeanFactoryAware
|
||||
if (StringUtils.hasLength(defaultDomain)) {
|
||||
namingStrategy.setDefaultDomain(defaultDomain);
|
||||
}
|
||||
|
||||
boolean uniqueName = this.environment.getProperty("spring.jmx.unique-names",
|
||||
Boolean.class, false);
|
||||
namingStrategy.setEnsureUniqueRuntimeObjectNames(uniqueName);
|
||||
|
||||
return namingStrategy;
|
||||
}
|
||||
|
||||
|
||||
@@ -290,6 +290,12 @@
|
||||
"description": "MBeanServer bean name.",
|
||||
"defaultValue": "mbeanServer"
|
||||
},
|
||||
{
|
||||
"name": "spring.jmx.unique-names",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "Whether to ensure that ObjectNames are modified in case of conflict.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
"name": "spring.jpa.open-in-view",
|
||||
"defaultValue": true
|
||||
|
||||
@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Tests for {@link JmxAutoConfiguration}.
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
public class JmxAutoConfigurationTests {
|
||||
|
||||
@@ -92,6 +93,7 @@ public class JmxAutoConfigurationTests {
|
||||
MockEnvironment env = new MockEnvironment();
|
||||
env.setProperty("spring.jmx.enabled", "true");
|
||||
env.setProperty("spring.jmx.default-domain", "my-test-domain");
|
||||
env.setProperty("spring.jmx.unique-names", "true");
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.setEnvironment(env);
|
||||
this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
|
||||
@@ -102,6 +104,8 @@ public class JmxAutoConfigurationTests {
|
||||
.getField(mBeanExporter, "namingStrategy");
|
||||
assertThat(ReflectionTestUtils.getField(naming, "defaultDomain"))
|
||||
.isEqualTo("my-test-domain");
|
||||
assertThat(ReflectionTestUtils.getField(naming, "ensureUniqueRuntimeObjectNames"))
|
||||
.isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user