Merge branch '1.3.x
This commit is contained in:
commit
b8ad9537a6
|
|
@ -22,6 +22,7 @@ import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.admin.SpringApplicationAdminMXBean;
|
import org.springframework.boot.admin.SpringApplicationAdminMXBean;
|
||||||
import org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar;
|
import org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
@ -34,6 +35,7 @@ import org.springframework.jmx.export.MBeanExporter;
|
||||||
* for internal use only.
|
* for internal use only.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Andy Wilkinson
|
||||||
* @since 1.3.0
|
* @since 1.3.0
|
||||||
* @see SpringApplicationAdminMXBean
|
* @see SpringApplicationAdminMXBean
|
||||||
*/
|
*/
|
||||||
|
|
@ -65,6 +67,7 @@ public class SpringApplicationAdminJmxAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
public SpringApplicationAdminMXBeanRegistrar springApplicationAdminRegistrar()
|
public SpringApplicationAdminMXBeanRegistrar springApplicationAdminRegistrar()
|
||||||
throws MalformedObjectNameException {
|
throws MalformedObjectNameException {
|
||||||
String jmxName = this.environment.getProperty(JMX_NAME_PROPERTY,
|
String jmxName = this.environment.getProperty(JMX_NAME_PROPERTY,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@ import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||||
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
import org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar;
|
||||||
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
|
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
|
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
|
||||||
|
|
@ -47,6 +50,7 @@ import static org.junit.Assert.fail;
|
||||||
* Tests for {@link SpringApplicationAdminJmxAutoConfiguration}.
|
* Tests for {@link SpringApplicationAdminJmxAutoConfiguration}.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
public class SpringApplicationAdminJmxAutoConfigurationTests {
|
public class SpringApplicationAdminJmxAutoConfigurationTests {
|
||||||
|
|
||||||
|
|
@ -130,6 +134,37 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
|
||||||
assertThat(actual).isEqualTo(String.valueOf(expected));
|
assertThat(actual).isEqualTo(String.valueOf(expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onlyRegisteredOnceWhenThereIsAChildContext() throws Exception {
|
||||||
|
SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder().web(false)
|
||||||
|
.sources(JmxAutoConfiguration.class,
|
||||||
|
SpringApplicationAdminJmxAutoConfiguration.class);
|
||||||
|
SpringApplicationBuilder childBuilder = parentBuilder
|
||||||
|
.child(JmxAutoConfiguration.class,
|
||||||
|
SpringApplicationAdminJmxAutoConfiguration.class)
|
||||||
|
.web(false);
|
||||||
|
ConfigurableApplicationContext parent = null;
|
||||||
|
ConfigurableApplicationContext child = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
parent = parentBuilder.run("--" + ENABLE_ADMIN_PROP);
|
||||||
|
child = childBuilder.run("--" + ENABLE_ADMIN_PROP);
|
||||||
|
BeanFactoryUtils.beanOfType(parent.getBeanFactory(),
|
||||||
|
SpringApplicationAdminMXBeanRegistrar.class);
|
||||||
|
this.thrown.expect(NoSuchBeanDefinitionException.class);
|
||||||
|
BeanFactoryUtils.beanOfType(child.getBeanFactory(),
|
||||||
|
SpringApplicationAdminMXBeanRegistrar.class);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (parent != null) {
|
||||||
|
parent.close();
|
||||||
|
}
|
||||||
|
if (child != null) {
|
||||||
|
child.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private ObjectName createDefaultObjectName() {
|
private ObjectName createDefaultObjectName() {
|
||||||
return createObjectName(DEFAULT_JMX_NAME);
|
return createObjectName(DEFAULT_JMX_NAME);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue