|
17 | 17 | package org.springframework.jmx.export;
|
18 | 18 |
|
19 | 19 | import java.util.ArrayList;
|
| 20 | +import java.util.Arrays; |
| 21 | +import java.util.Collection; |
20 | 22 | import java.util.Collections;
|
21 | 23 | import java.util.HashMap;
|
22 | 24 | import java.util.List;
|
@@ -643,6 +645,28 @@ public void testMBeanIsUnregisteredForRuntimeExceptionDuringInitialization() thr
|
643 | 645 | ObjectNameManager.getInstance(objectName2));
|
644 | 646 | }
|
645 | 647 |
|
| 648 | + @Test |
| 649 | + public void testIgnoreBeanName() throws MalformedObjectNameException { |
| 650 | + DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); |
| 651 | + String firstBeanName = "spring:type=TestBean"; |
| 652 | + factory.registerSingleton(firstBeanName, new TestBean("test")); |
| 653 | + String secondBeanName = "spring:type=TestBean2"; |
| 654 | + factory.registerSingleton(secondBeanName, new TestBean("test2")); |
| 655 | + |
| 656 | + MBeanExporter exporter = new MBeanExporter(); |
| 657 | + exporter.setServer(getServer()); |
| 658 | + exporter.setAssembler(new NamedBeanAutodetectCapableMBeanInfoAssemblerStub(firstBeanName, secondBeanName)); |
| 659 | + exporter.setBeanFactory(factory); |
| 660 | + exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL); |
| 661 | + exporter.addExcludedBean(secondBeanName); |
| 662 | + |
| 663 | + start(exporter); |
| 664 | + assertIsRegistered("Bean not autodetected in (AUTODETECT_ALL) mode", |
| 665 | + ObjectNameManager.getInstance(firstBeanName)); |
| 666 | + assertIsNotRegistered("Bean should have been excluded", |
| 667 | + ObjectNameManager.getInstance(secondBeanName)); |
| 668 | + } |
| 669 | + |
646 | 670 | private ConfigurableApplicationContext load(String context) {
|
647 | 671 | return new ClassPathXmlApplicationContext(context, getClass());
|
648 | 672 | }
|
@@ -763,15 +787,15 @@ public RuntimeExceptionThrowingConstructorBean() {
|
763 | 787 | private static final class NamedBeanAutodetectCapableMBeanInfoAssemblerStub extends
|
764 | 788 | SimpleReflectiveMBeanInfoAssembler implements AutodetectCapableMBeanInfoAssembler {
|
765 | 789 |
|
766 |
| - private String namedBean; |
| 790 | + private Collection<String> namedBeans; |
767 | 791 |
|
768 |
| - public NamedBeanAutodetectCapableMBeanInfoAssemblerStub(String namedBean) { |
769 |
| - this.namedBean = namedBean; |
| 792 | + public NamedBeanAutodetectCapableMBeanInfoAssemblerStub(String... namedBeans) { |
| 793 | + this.namedBeans = Arrays.asList(namedBeans); |
770 | 794 | }
|
771 | 795 |
|
772 | 796 | @Override
|
773 | 797 | public boolean includeBean(Class<?> beanClass, String beanName) {
|
774 |
| - return this.namedBean.equals(beanName); |
| 798 | + return this.namedBeans.contains(beanName); |
775 | 799 | }
|
776 | 800 | }
|
777 | 801 |
|
|
0 commit comments