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; ...@@ -49,6 +49,7 @@ import org.springframework.util.StringUtils;
* *
* @author Christian Dupuis * @author Christian Dupuis
* @author Madhura Bhave * @author Madhura Bhave
* @author Artsiom Yudovin
*/ */
@Configuration @Configuration
@ConditionalOnClass({ MBeanExporter.class }) @ConditionalOnClass({ MBeanExporter.class })
...@@ -93,6 +94,11 @@ public class JmxAutoConfiguration implements EnvironmentAware, BeanFactoryAware ...@@ -93,6 +94,11 @@ public class JmxAutoConfiguration implements EnvironmentAware, BeanFactoryAware
if (StringUtils.hasLength(defaultDomain)) { if (StringUtils.hasLength(defaultDomain)) {
namingStrategy.setDefaultDomain(defaultDomain); namingStrategy.setDefaultDomain(defaultDomain);
} }
boolean uniqueName = this.environment.getProperty("spring.jmx.unique-names",
Boolean.class, false);
namingStrategy.setEnsureUniqueRuntimeObjectNames(uniqueName);
return namingStrategy; return namingStrategy;
} }
......
...@@ -290,6 +290,12 @@ ...@@ -290,6 +290,12 @@
"description": "MBeanServer bean name.", "description": "MBeanServer bean name.",
"defaultValue": "mbeanServer" "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", "name": "spring.jpa.open-in-view",
"defaultValue": true "defaultValue": true
......
...@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link JmxAutoConfiguration}. * Tests for {@link JmxAutoConfiguration}.
* *
* @author Christian Dupuis * @author Christian Dupuis
* @author Artsiom Yudovin
*/ */
public class JmxAutoConfigurationTests { public class JmxAutoConfigurationTests {
...@@ -92,6 +93,7 @@ public class JmxAutoConfigurationTests { ...@@ -92,6 +93,7 @@ public class JmxAutoConfigurationTests {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("spring.jmx.enabled", "true"); env.setProperty("spring.jmx.enabled", "true");
env.setProperty("spring.jmx.default-domain", "my-test-domain"); env.setProperty("spring.jmx.default-domain", "my-test-domain");
env.setProperty("spring.jmx.unique-names", "true");
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.setEnvironment(env); this.context.setEnvironment(env);
this.context.register(TestConfiguration.class, JmxAutoConfiguration.class); this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
...@@ -102,6 +104,8 @@ public class JmxAutoConfigurationTests { ...@@ -102,6 +104,8 @@ public class JmxAutoConfigurationTests {
.getField(mBeanExporter, "namingStrategy"); .getField(mBeanExporter, "namingStrategy");
assertThat(ReflectionTestUtils.getField(naming, "defaultDomain")) assertThat(ReflectionTestUtils.getField(naming, "defaultDomain"))
.isEqualTo("my-test-domain"); .isEqualTo("my-test-domain");
assertThat(ReflectionTestUtils.getField(naming, "ensureUniqueRuntimeObjectNames"))
.isEqualTo(true);
} }
@Test @Test
......
...@@ -100,6 +100,7 @@ content into your application. Rather, pick only the properties that you need. ...@@ -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.default-domain= # JMX domain name.
spring.jmx.enabled=true # Expose management beans to the JMX domain. spring.jmx.enabled=true # Expose management beans to the JMX domain.
spring.jmx.server=mbeanServer # MBeanServer bean name. 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]) # Email ({sc-spring-boot-autoconfigure}/mail/MailProperties.{sc-ext}[MailProperties])
spring.mail.default-encoding=UTF-8 # Default MimeMessage encoding. 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