Spring Framework
  1. Spring Framework
  2. SPR-10265

ConfigurationClassBeanDefinitionReader: Scoped-Proxy BeanDefinitions cannot be overriden by other configuration classes

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 3.2.1
    • Fix Version/s: 3.2.2
    • Component/s: Core
    • Labels:
      None

      Description

      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();
      		}
      

        Activity

        Hide
        Juergen Hoeller added a comment -

        Good point - fixed for 3.2.2!

        Juergen

        Show
        Juergen Hoeller added a comment - Good point - fixed for 3.2.2! Juergen

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Jose Luis Martin
            Last updater:
            Juergen Hoeller
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              1 year, 11 weeks, 1 day ago