Commit 1a3f08d7 authored by artsiom's avatar artsiom Committed by Stephane Nicoll

Add global support for JMX unique names

See gh-13990
parent c071f34a
......@@ -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
......
......@@ -100,6 +100,7 @@ content into your application. Rather, pick only the properties that you need.
spring.jmx.default-domain= # JMX domain name.
spring.jmx.enabled=true # Expose management beans to the JMX domain.
spring.jmx.server=mbeanServer # MBeanServer bean name.
spring.jmx.unique-names=false # Set if unique runtime object names should be ensured.
# Email ({sc-spring-boot-autoconfigure}/mail/MailProperties.{sc-ext}[MailProperties])
spring.mail.default-encoding=UTF-8 # Default MimeMessage encoding.
......
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