Add global support for JMX unique names

See gh-13990
This commit is contained in:
artsiom 2018-08-03 00:45:11 +03:00 committed by Stephane Nicoll
parent c071f34a4a
commit 1a3f08d772
4 changed files with 17 additions and 0 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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.