Fix ParentAwareNamingStrategy and JMX auto-config
Fix ParentAwareNamingStrategy to set ObjectName properties for the 'identity' and 'context' attributes. Also update JmxAutoConfiguration to ensure that the ParentAwareNamingStrategy is created in each context and that the `mbeanExporter` bean is created. Prior to this commit the nested @EnableMBeanExport class always meant that the mbeanExporter condition never matched. Fixes gh-2243
This commit is contained in:
@@ -74,7 +74,6 @@ public class JmxAutoConfigurationTests {
|
||||
this.context.setEnvironment(env);
|
||||
this.context.register(JmxAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
assertNotNull(this.context.getBean(MBeanExporter.class));
|
||||
}
|
||||
|
||||
@@ -86,7 +85,6 @@ public class JmxAutoConfigurationTests {
|
||||
this.context.setEnvironment(env);
|
||||
this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
this.context.getBean(MBeanExporter.class);
|
||||
}
|
||||
|
||||
@@ -99,17 +97,16 @@ public class JmxAutoConfigurationTests {
|
||||
this.context.setEnvironment(env);
|
||||
this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
|
||||
MBeanExporter mBeanExporter = this.context.getBean(MBeanExporter.class);
|
||||
assertNotNull(mBeanExporter);
|
||||
MetadataNamingStrategy naming = (MetadataNamingStrategy) ReflectionTestUtils
|
||||
.getField(mBeanExporter, "metadataNamingStrategy");
|
||||
.getField(mBeanExporter, "namingStrategy");
|
||||
assertEquals("my-test-domain",
|
||||
ReflectionTestUtils.getField(naming, "defaultDomain"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParentContext() {
|
||||
public void testBasicParentContext() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(JmxAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
@@ -120,6 +117,18 @@ public class JmxAutoConfigurationTests {
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParentContext() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(JmxAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
AnnotationConfigApplicationContext parent = this.context;
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.setParent(parent);
|
||||
this.context.register(JmxAutoConfiguration.class, TestConfiguration.class);
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class TestConfiguration {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user