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:
Juergen Hoeller
2012-10-31 02:07:09 +01:00
committed by unknown
parent 8f8e517c0d
commit 0e0200769d
8 changed files with 69 additions and 18 deletions

View File

@@ -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();
}
}

View File

@@ -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();

View File

@@ -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 {
}

View File

@@ -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"/>