ManagedResource annotation supports placeholders for String attributes
In particular, the specified object name may use a placeholder for its domain part now, allowing for several instances of the MBean to be registered against the same MBeanServer from different applications. Issue: SPR-8244
This commit is contained in:
@@ -47,6 +47,7 @@ public class AnnotationLazyInitMBeanTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testLazyAssembling() throws Exception {
|
||||
System.setProperty("domain", "bean");
|
||||
ConfigurableApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyAssembling.xml");
|
||||
try {
|
||||
@@ -73,6 +74,7 @@ public class AnnotationLazyInitMBeanTests extends TestCase {
|
||||
assertEquals("Invalid name returned", "Juergen Hoeller", name);
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("domain");
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.management.ObjectName;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
@@ -62,6 +63,7 @@ public class EnableMBeanExportConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void testLazyAssembling() throws Exception {
|
||||
System.setProperty("domain", "bean");
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(LazyAssemblingConfiguration.class);
|
||||
try {
|
||||
@@ -88,6 +90,7 @@ public class EnableMBeanExportConfigurationTests {
|
||||
assertEquals("Invalid name returned", "Juergen Hoeller", name);
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("domain");
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
@@ -130,6 +133,11 @@ public class EnableMBeanExportConfigurationTests {
|
||||
@EnableMBeanExport(server="server", registration=RegistrationPolicy.REPLACE_EXISTING)
|
||||
static class LazyAssemblingConfiguration {
|
||||
|
||||
@Bean
|
||||
public PropertyPlaceholderConfigurer ppc() {
|
||||
return new PropertyPlaceholderConfigurer();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MBeanServerFactoryBean server() throws Exception {
|
||||
return new MBeanServerFactoryBean();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -19,7 +19,7 @@ package org.springframework.jmx.export.annotation;
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@ManagedResource(objectName = "bean:name=testBean5")
|
||||
@ManagedResource("${domain}:name=testBean5")
|
||||
public class FactoryCreatedAnnotationTestBean extends AnnotationTestBean {
|
||||
|
||||
}
|
||||
|
||||
@@ -7,14 +7,16 @@
|
||||
|
||||
<context:mbean-export server="server" registration="replaceExisting"/>
|
||||
|
||||
<bean id="server" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
|
||||
<context:property-placeholder/>
|
||||
|
||||
<bean name="bean:name=testBean4" class="org.springframework.jmx.export.annotation.AnnotationTestBean" lazy-init="true">
|
||||
<bean id="server" class="org.springframework.jmx.support.MBeanServerFactoryBean"/>
|
||||
|
||||
<bean name="testBean4" class="org.springframework.jmx.export.annotation.AnnotationTestBean" lazy-init="true">
|
||||
<property name="name" value="TEST"/>
|
||||
<property name="age" value="100"/>
|
||||
</bean>
|
||||
|
||||
<bean name="bean:name=testBean5" class="org.springframework.jmx.export.annotation.AnnotationTestBeanFactory"/>
|
||||
<bean name="testBean5" class="org.springframework.jmx.export.annotation.AnnotationTestBeanFactory"/>
|
||||
|
||||
<bean name="spring:mbean=true" class="org.springframework.jmx.export.TestDynamicMBean" lazy-init="true"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user