You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression in 4.0.0 - A scoped-proxy bean cannot override another bean [SPR-11229] #15854
The original bean is configured thru Java Config in the AppConfiguration class.
The overriding bean is configured thru overridingApplicationContext.xml.
There is a test that checks that the correct string is returned for each bean ("Hello Lisa" for the original not-overriden app-ctx, "Hello Maria" for the overriden one).
If Spring 3.2.5.RELEASE is used in the pom.xml, the test always passes.
If Spring 4.0.0.RELEASE is used in the pom.xml and the overriding bean is a scoped-proxy, the test fails.
If Spring 4.0.0.RELEASE is used in the pom.xml and the overriding bean is NOT a scoped-proxy, the test passes.
Changing the scope of the overriding bean or the original bean has no effect in the results
Making the original bean also a scoped-proxy has no effect either
Configuring the original bean with XML instead of Java Config makes it work (???): removing the component-scan and adding this to originalApplicationContext.xml instead makes it work:
3.2.6 is not affected.
In 4.0.0, with aop:scoped-proxy, I see:
INFO: Overriding bean definition for bean 'theService': replacing [Root bean: class [org.springframework.aop.scope.ScopedProxyFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in BeanDefinition defined in class path resource [�overridingApplicationContext.xml]] with [Root bean: class [null]; scope=singleton; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=appConfiguration; factoryMethodName=theService; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/flozano/testbeanoverride/config/AppConfiguration.class]]
while without aop:scoped-proxy, I see:
INFO: Skipping bean definition for [BeanMethod:name=theService,declaringClass=com.flozano.testbeanoverride.config.AppConfiguration]: a definition for bean 'theService' already exists. This top-level bean definition is considered as an override.
Looks like our overriding check doesn't properly detect the scenario there. With a Java/XML mix, it's not just the order of registration that matters, since XML is typically processed first but is still supposed to override same-named @Bean methods. That special override check seems to fail in your scenario.
If you're defining both beans in XML, it is simply the order of registration that matters, so you never run into that part of the algorithm and never experience such a mismatch.
Turns out that this is a side effect of #15236 where the bean definition 'role' is being considered in the overriding algorithm now. Since scoped proxy definitions were marked as ROLE_INFRASTRUCTURE, they were excluded according to that new rule there. I've changed the scoped proxy role to use the same role as the target bean definition, which makes your scenario work properly again.
Dec 17, 2013 8:24:48 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@32fcc6e8: startup date [Tue Dec 17 08:24:48 CET 2013]; root of context hierarchy
Dec 17, 2013 8:24:49 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [originalApplicationContext.xml]
Dec 17, 2013 8:24:49 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@32fcc6e8: startup date [Tue Dec 17 08:24:48 CET 2013]; root of context hierarchy
Dec 17, 2013 8:24:49 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1fabeb4c: startup date [Tue Dec 17 08:24:49 CET 2013]; root of context hierarchy
Dec 17, 2013 8:24:49 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [�overridingApplicationContext.xml]
Dec 17, 2013 8:24:49 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [originalApplicationContext.xml]
Dec 17, 2013 8:24:49 AM org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader isOverriddenByExistingDefinition
INFO: Skipping bean definition for [BeanMethod:name=theService,declaringClass=com.flozano.testbeanoverride.config.AppConfiguration]: a definition for bean 'theService' already exists. This top-level bean definition is considered as an override.
Dec 17, 2013 8:24:49 AM org.springframework.context.support.SimpleThreadScope registerDestructionCallback
WARNING: SimpleThreadScope does not support descruction callbacks. Consider using a RequestScope in a Web environment.
Dec 17, 2013 8:24:49 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@1fabeb4c: startup date [Tue Dec 17 08:24:49 CET 2013]; root of context hierarchy
Activity
spring-projects-issues commentedon Dec 16, 2013
Francisco Lozano commented
3.2.6 is not affected.
In 4.0.0, with aop:scoped-proxy, I see:
while without aop:scoped-proxy, I see:
spring-projects-issues commentedon Dec 16, 2013
Juergen Hoeller commented
Looks like our overriding check doesn't properly detect the scenario there. With a Java/XML mix, it's not just the order of registration that matters, since XML is typically processed first but is still supposed to override same-named
@Beanmethods. That special override check seems to fail in your scenario.If you're defining both beans in XML, it is simply the order of registration that matters, so you never run into that part of the algorithm and never experience such a mismatch.
Juergen
spring-projects-issues commentedon Dec 16, 2013
Juergen Hoeller commented
Turns out that this is a side effect of #15236 where the bean definition 'role' is being considered in the overriding algorithm now. Since scoped proxy definitions were marked as ROLE_INFRASTRUCTURE, they were excluded according to that new rule there. I've changed the scoped proxy role to use the same role as the target bean definition, which makes your scenario work properly again.
Juergen
spring-projects-issues commentedon Dec 16, 2013
Francisco Lozano commented
Wow that was fast, thank you. I'll wait for 4.0.1 then.
spring-projects-issues commentedon Dec 16, 2013
Juergen Hoeller commented
You could try a 4.0.1 snapshot - see http://projects.spring.io/spring-framework/ for repo information. Would be great to verify that it actually works for you now...
Juergen
spring-projects-issues commentedon Dec 16, 2013
Francisco Lozano commented
I can confirm it works with the 4.0.1 SNAPSHOT:
spring-projects-issues commentedon Dec 17, 2013
Juergen Hoeller commented
Great to know! Thanks for giving it a try...
Juergen