Allow MBeans to be excluded additively
Previously, one could only set the list of bean names to exclude from auto-detection and there was no way to add additional bean names. MBeanExporter now exposes a addExcludedBean method that can be invoked during the initialization phase to add bean names to ignore. Issue: SPR-12686
This commit is contained in:
@@ -161,7 +161,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
||||
private boolean exposeManagedResourceClassLoader = true;
|
||||
|
||||
/** A set of bean names that should be excluded from autodetection */
|
||||
private Set<String> excludedBeans;
|
||||
private Set<String> excludedBeans = new HashSet<String>();
|
||||
|
||||
/** The MBeanExporterListeners registered with this exporter. */
|
||||
private MBeanExporterListener[] listeners;
|
||||
@@ -314,7 +314,18 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
||||
* Set the list of names for beans that should be excluded from autodetection.
|
||||
*/
|
||||
public void setExcludedBeans(String... excludedBeans) {
|
||||
this.excludedBeans = (excludedBeans != null ? new HashSet<String>(Arrays.asList(excludedBeans)) : null);
|
||||
this.excludedBeans.clear();
|
||||
if (excludedBeans != null) {
|
||||
this.excludedBeans.addAll(Arrays.asList(excludedBeans));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the name of bean that should be excluded from autodetection.
|
||||
*/
|
||||
public void addExcludedBean(String excludedBean) {
|
||||
Assert.notNull(excludedBean, "ExcludedBean must not be null");
|
||||
this.excludedBeans.add(excludedBean);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -922,10 +933,9 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
||||
* Indicates whether or not a particular bean name is present in the excluded beans list.
|
||||
*/
|
||||
private boolean isExcluded(String beanName) {
|
||||
return (this.excludedBeans != null &&
|
||||
(this.excludedBeans.contains(beanName) ||
|
||||
(beanName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX) &&
|
||||
this.excludedBeans.contains(beanName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length())))));
|
||||
return (this.excludedBeans.contains(beanName) ||
|
||||
(beanName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX) &&
|
||||
this.excludedBeans.contains(beanName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length()))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user