Skip to content

ConfigurationClassBeanDefinitionReader: Scoped-Proxy BeanDefinitions cannot be overriden by other configuration classes [SPR-10265] #14899

@spring-projects-issues

Description

@spring-projects-issues

Jose Luis Martin opened SPR-10265 and commented

ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod() register scoped proxies using a RootBeanDefinition from ScopedProxyCreator.createScopedProxy() so the BeanDefinition cannot be overriden by other configuration classes.


// replace the original bean definition with the target one, if necessary
  BeanDefinition beanDefToRegister = beanDef;
		if (proxyMode != ScopedProxyMode.NO) {
			BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(
					new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLASS);
			beanDefToRegister = proxyDef.getBeanDefinition();
		}

I guess it should register a ConfigurationClassBeanDefinition instead. For example:


	// replace the original bean definition with the target one, if necessary
		BeanDefinition beanDefToRegister = beanDef;
		if (proxyMode != ScopedProxyMode.NO) {
			BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(
					new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLASS);
			beanDefToRegister = new ConfigurationClassBeanDefinition((RootBeanDefinition) proxyDef.getBeanDefinition(), configClass);
		}

that uses the following constructor in ConfigurationClassBeanDefinition:

public ConfigurationClassBeanDefinition(RootBeanDefinition original, ConfigurationClass configClass) {
			super(original);
			this.annotationMetadata = configClass.getMetadata();
		}

Affects: 3.2.1

Reference URL: http://stackoverflow.com/questions/14692561/how-do-i-override-a-scoped-bean-for-tests

Referenced from: commits 6b82d29

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions