Handle scoped proxy properly in MBeanExporter
Previously, if a bean has a scoped proxy and is annotated to be exposed to the JMX domain, both the scoped proxy and the target instance were exposed in the JMX domain, resulting in a duplicate entries. Worse, if such bean defines an explicit name, the application wouldn't start because of a name conflict. This commit deals explicitely with scoped proxy and make sure to only expose the relevant bean. Issue: SPR-12529
This commit is contained in:
@@ -39,6 +39,7 @@ import javax.management.modelmbean.ModelMBeanInfo;
|
||||
import javax.management.modelmbean.RequiredModelMBean;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.scope.ScopedProxyUtils;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.target.LazyInitTargetSource;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
@@ -891,8 +892,9 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
||||
if (beanClass != null && callback.include(beanClass, beanName)) {
|
||||
boolean lazyInit = isBeanDefinitionLazyInit(this.beanFactory, beanName);
|
||||
Object beanInstance = (!lazyInit ? this.beanFactory.getBean(beanName) : null);
|
||||
if (!this.beans.containsValue(beanName) && (beanInstance == null ||
|
||||
!CollectionUtils.containsInstance(this.beans.values(), beanInstance))) {
|
||||
if (!ScopedProxyUtils.isScopedTarget(beanName) && !this.beans.containsValue(beanName) &&
|
||||
(beanInstance == null ||
|
||||
!CollectionUtils.containsInstance(this.beans.values(), beanInstance))) {
|
||||
// Not already registered for JMX exposure.
|
||||
this.beans.put(beanName, (beanInstance != null ? beanInstance : beanName));
|
||||
if (logger.isInfoEnabled()) {
|
||||
|
||||
Reference in New Issue
Block a user