AbstractInterceptorDrivenBeanDefinitionDecorator copies autowire settings just like ScopedProxyUtils does (SPR-6974)
This commit is contained in:
@@ -21,9 +21,9 @@ import java.util.List;
|
|||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
import org.springframework.aop.framework.ProxyFactoryBean;
|
import org.springframework.aop.framework.ProxyFactoryBean;
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||||
|
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.beans.factory.support.ManagedList;
|
import org.springframework.beans.factory.support.ManagedList;
|
||||||
@@ -63,7 +63,7 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
|
|||||||
|
|
||||||
// get the root bean name - will be the name of the generated proxy factory bean
|
// get the root bean name - will be the name of the generated proxy factory bean
|
||||||
String existingBeanName = definitionHolder.getBeanName();
|
String existingBeanName = definitionHolder.getBeanName();
|
||||||
BeanDefinition existingDefinition = definitionHolder.getBeanDefinition();
|
BeanDefinition targetDefinition = definitionHolder.getBeanDefinition();
|
||||||
|
|
||||||
// delegate to subclass for interceptor definition
|
// delegate to subclass for interceptor definition
|
||||||
BeanDefinition interceptorDefinition = createInterceptorDefinition(node);
|
BeanDefinition interceptorDefinition = createInterceptorDefinition(node);
|
||||||
@@ -74,22 +74,22 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
|
|||||||
|
|
||||||
BeanDefinitionHolder result = definitionHolder;
|
BeanDefinitionHolder result = definitionHolder;
|
||||||
|
|
||||||
if (!isProxyFactoryBeanDefinition(existingDefinition)) {
|
if (!isProxyFactoryBeanDefinition(targetDefinition)) {
|
||||||
// create the proxy definition
|
// create the proxy definition
|
||||||
RootBeanDefinition proxyDefinition = new RootBeanDefinition();
|
RootBeanDefinition proxyDefinition = new RootBeanDefinition();
|
||||||
// create proxy factory bean definition
|
// create proxy factory bean definition
|
||||||
proxyDefinition.setBeanClass(ProxyFactoryBean.class);
|
proxyDefinition.setBeanClass(ProxyFactoryBean.class);
|
||||||
|
|
||||||
// set up property values
|
|
||||||
MutablePropertyValues mpvs = new MutablePropertyValues();
|
|
||||||
proxyDefinition.setPropertyValues(mpvs);
|
|
||||||
|
|
||||||
// set the target
|
// set the target
|
||||||
mpvs.add("target", existingDefinition);
|
proxyDefinition.getPropertyValues().add("target", targetDefinition);
|
||||||
|
|
||||||
// create the interceptor names list
|
// create the interceptor names list
|
||||||
mpvs.add("interceptorNames", new ManagedList<String>());
|
proxyDefinition.getPropertyValues().add("interceptorNames", new ManagedList<String>());
|
||||||
|
// copy autowire settings from original bean definition.
|
||||||
|
proxyDefinition.setAutowireCandidate(targetDefinition.isAutowireCandidate());
|
||||||
|
proxyDefinition.setPrimary(targetDefinition.isPrimary());
|
||||||
|
if (targetDefinition instanceof AbstractBeanDefinition) {
|
||||||
|
proxyDefinition.copyQualifiersFrom((AbstractBeanDefinition) targetDefinition);
|
||||||
|
}
|
||||||
|
// wrap it in a BeanDefinitionHolder with bean name
|
||||||
result = new BeanDefinitionHolder(proxyDefinition, existingBeanName);
|
result = new BeanDefinitionHolder(proxyDefinition, existingBeanName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +99,8 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void addInterceptorNameToList(String interceptorName, BeanDefinition beanDefinition) {
|
private void addInterceptorNameToList(String interceptorName, BeanDefinition beanDefinition) {
|
||||||
List<String> list = (List<String>) beanDefinition.getPropertyValues().getPropertyValue("interceptorNames").getValue();
|
List<String> list = (List<String>)
|
||||||
|
beanDefinition.getPropertyValues().getPropertyValue("interceptorNames").getValue();
|
||||||
list.add(interceptorName);
|
list.add(interceptorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2009 the original author or authors.
|
* Copyright 2002-2010 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -53,28 +53,29 @@ public abstract class ScopedProxyUtils {
|
|||||||
|
|
||||||
// Create a scoped proxy definition for the original bean name,
|
// Create a scoped proxy definition for the original bean name,
|
||||||
// "hiding" the target bean in an internal target definition.
|
// "hiding" the target bean in an internal target definition.
|
||||||
RootBeanDefinition scopedProxyDefinition = new RootBeanDefinition(ScopedProxyFactoryBean.class);
|
RootBeanDefinition proxyDefinition = new RootBeanDefinition(ScopedProxyFactoryBean.class);
|
||||||
scopedProxyDefinition.setOriginatingBeanDefinition(definition.getBeanDefinition());
|
proxyDefinition.setOriginatingBeanDefinition(definition.getBeanDefinition());
|
||||||
scopedProxyDefinition.setSource(definition.getSource());
|
proxyDefinition.setSource(definition.getSource());
|
||||||
scopedProxyDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
proxyDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||||
|
|
||||||
String targetBeanName = getTargetBeanName(originalBeanName);
|
String targetBeanName = getTargetBeanName(originalBeanName);
|
||||||
scopedProxyDefinition.getPropertyValues().add("targetBeanName", targetBeanName);
|
proxyDefinition.getPropertyValues().add("targetBeanName", targetBeanName);
|
||||||
|
|
||||||
if (proxyTargetClass) {
|
if (proxyTargetClass) {
|
||||||
targetDefinition.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
|
targetDefinition.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
|
||||||
// ScopedFactoryBean's "proxyTargetClass" default is TRUE, so we don't need to set it explicitly here.
|
// ScopedFactoryBean's "proxyTargetClass" default is TRUE, so we don't need to set it explicitly here.
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
scopedProxyDefinition.getPropertyValues().add("proxyTargetClass", Boolean.FALSE);
|
proxyDefinition.getPropertyValues().add("proxyTargetClass", Boolean.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy autowire settings from original bean definition.
|
// Copy autowire settings from original bean definition.
|
||||||
|
proxyDefinition.setAutowireCandidate(targetDefinition.isAutowireCandidate());
|
||||||
|
proxyDefinition.setPrimary(targetDefinition.isPrimary());
|
||||||
if (targetDefinition instanceof AbstractBeanDefinition) {
|
if (targetDefinition instanceof AbstractBeanDefinition) {
|
||||||
scopedProxyDefinition.copyQualifiersFrom((AbstractBeanDefinition) targetDefinition);
|
proxyDefinition.copyQualifiersFrom((AbstractBeanDefinition) targetDefinition);
|
||||||
}
|
}
|
||||||
scopedProxyDefinition.setAutowireCandidate(targetDefinition.isAutowireCandidate());
|
|
||||||
scopedProxyDefinition.setPrimary(targetDefinition.isPrimary());
|
|
||||||
// The target bean should be ignored in favor of the scoped proxy.
|
// The target bean should be ignored in favor of the scoped proxy.
|
||||||
targetDefinition.setAutowireCandidate(false);
|
targetDefinition.setAutowireCandidate(false);
|
||||||
targetDefinition.setPrimary(false);
|
targetDefinition.setPrimary(false);
|
||||||
@@ -84,7 +85,7 @@ public abstract class ScopedProxyUtils {
|
|||||||
|
|
||||||
// Return the scoped proxy definition as primary bean definition
|
// Return the scoped proxy definition as primary bean definition
|
||||||
// (potentially an inner bean).
|
// (potentially an inner bean).
|
||||||
return new BeanDefinitionHolder(scopedProxyDefinition, originalBeanName, definition.getAliases());
|
return new BeanDefinitionHolder(proxyDefinition, originalBeanName, definition.getAliases());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user