@EnableMBeanExport supports placeholders for its attributes now

Issue: SPR-11105
This commit is contained in:
Juergen Hoeller
2013-11-22 23:18:47 +01:00
parent ad402dcb4a
commit 009e362709
2 changed files with 73 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ import org.springframework.jmx.export.TestDynamicMBean;
import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.mock.env.MockEnvironment;
import static org.junit.Assert.*;
@@ -61,6 +62,26 @@ public class EnableMBeanExportConfigurationTests {
}
}
@Test
public void testPlaceholderBased() throws Exception {
MockEnvironment env = new MockEnvironment();
env.setProperty("serverName", "server");
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setEnvironment(env);
ctx.register(PlaceholderBasedConfiguration.class);
ctx.refresh();
try {
MBeanServer server = (MBeanServer) ctx.getBean("server");
ObjectName oname = ObjectNameManager.getInstance("bean:name=testBean4");
assertNotNull(server.getObjectInstance(oname));
String name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "TEST", name);
}
finally {
ctx.close();
}
}
@Test
public void testLazyAssembling() throws Exception {
System.setProperty("domain", "bean");
@@ -110,6 +131,7 @@ public class EnableMBeanExportConfigurationTests {
}
}
@Configuration
@EnableMBeanExport(server = "server")
static class LazyNamingConfiguration {
@@ -129,6 +151,27 @@ public class EnableMBeanExportConfigurationTests {
}
}
@Configuration
@EnableMBeanExport(server = "${serverName}")
static class PlaceholderBasedConfiguration {
@Bean
public MBeanServerFactoryBean server() throws Exception {
return new MBeanServerFactoryBean();
}
@Bean
@Lazy
public AnnotationTestBean testBean() {
AnnotationTestBean bean = new AnnotationTestBean();
bean.setName("TEST");
bean.setAge(100);
return bean;
}
}
@Configuration
@EnableMBeanExport(server="server", registration=RegistrationPolicy.REPLACE_EXISTING)
static class LazyAssemblingConfiguration {
@@ -178,6 +221,7 @@ public class EnableMBeanExportConfigurationTests {
}
}
@Configuration
@ComponentScan(excludeFilters = @ComponentScan.Filter(value=Configuration.class))
@EnableMBeanExport(server = "server")