Support for Jmx (and Integration) autoconfig in parent contexts

When there are parent contexts we already had a strategy for registering
the actuator endpoints, but not the regular JMX or Integration MBeans.
This chnage makes the autoconfigs for JMX aware of the parent context.

Also adds a sample with a parent context.

See gh-847
This commit is contained in:
Dave Syer
2014-06-10 09:13:19 +01:00
parent 5adbf32c18
commit 36130b27e1
17 changed files with 537 additions and 4 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.integration;
import org.junit.Test;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.integration.support.channel.HeaderChannelRegistry;
@@ -29,10 +30,18 @@ import static org.junit.Assert.assertNotNull;
*/
public class IntegrationAutoConfigurationTests {
private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Test
public void integrationIsAvailable() {
this.context.register(IntegrationAutoConfiguration.class);
this.context.refresh();
assertNotNull(this.context.getBean(HeaderChannelRegistry.class));
this.context.close();
}
@Test
public void addJmxAuto() {
this.context.register(JmxAutoConfiguration.class,
IntegrationAutoConfiguration.class);
this.context.refresh();
@@ -40,4 +49,18 @@ public class IntegrationAutoConfigurationTests {
this.context.close();
}
@Test
public void parentContext() {
this.context.register(IntegrationAutoConfiguration.class);
this.context.refresh();
AnnotationConfigApplicationContext parent = this.context;
this.context = new AnnotationConfigApplicationContext();
this.context.setParent(parent);
this.context.register(IntegrationAutoConfiguration.class);
this.context.refresh();
assertNotNull(this.context.getBean(HeaderChannelRegistry.class));
((ConfigurableApplicationContext) this.context.getParent()).close();
this.context.close();
}
}

View File

@@ -21,6 +21,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -51,6 +52,9 @@ public class JmxAutoConfigurationTests {
public void tearDown() {
if (this.context != null) {
this.context.close();
if (this.context.getParent() != null) {
((ConfigurableApplicationContext) this.context.getParent()).close();
}
}
}
@@ -104,6 +108,18 @@ public class JmxAutoConfigurationTests {
ReflectionTestUtils.getField(naming, "defaultDomain"));
}
@Test
public void testParentContext() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(JmxAutoConfiguration.class);
this.context.refresh();
AnnotationConfigApplicationContext parent = this.context;
this.context = new AnnotationConfigApplicationContext();
this.context.setParent(parent);
this.context.register(JmxAutoConfiguration.class);
this.context.refresh();
}
@Configuration
public static class TestConfiguration {