Always preserve target class for configuration classes in case of auto-proxying
Issue: SPR-10561
This commit is contained in:
@@ -27,6 +27,7 @@ import java.util.Set;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
|
||||
import org.springframework.beans.PropertyValues;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
@@ -253,8 +254,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
||||
throw new IllegalStateException(
|
||||
"postProcessBeanFactory already called for this post-processor against " + beanFactory);
|
||||
}
|
||||
this.factoriesPostProcessed.add((factoryId));
|
||||
if (!this.registriesPostProcessed.contains((factoryId))) {
|
||||
this.factoriesPostProcessed.add(factoryId);
|
||||
if (!this.registriesPostProcessed.contains(factoryId)) {
|
||||
// BeanDefinitionRegistryPostProcessor hook apparently not supported...
|
||||
// Simply call processConfigurationClasses lazily at this point then.
|
||||
processConfigBeanDefinitions((BeanDefinitionRegistry) beanFactory);
|
||||
@@ -359,7 +360,10 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
||||
ConfigurationClassEnhancer enhancer = new ConfigurationClassEnhancer();
|
||||
for (Map.Entry<String, AbstractBeanDefinition> entry : configBeanDefs.entrySet()) {
|
||||
AbstractBeanDefinition beanDef = entry.getValue();
|
||||
// If a @Configuration class gets proxied, always proxy the target class
|
||||
beanDef.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
|
||||
try {
|
||||
// Set enhanced subclass of the user-specified bean class
|
||||
Class<?> configClass = beanDef.resolveBeanClass(this.beanClassLoader);
|
||||
Class<?> enhancedClass = enhancer.enhance(configClass);
|
||||
if (configClass != enhancedClass) {
|
||||
|
||||
Reference in New Issue
Block a user