Description
Francisco Lozano opened SPR-11229 and commented
It seems the behavior between 4.0.0.RELEASE and 3.2.5.RELEASE has changed with regard to bean overrides.
In the sample project (https://github.com/flozano/spring-override-behavior-changed) there is a singleton bean with a "sayHello" method, which returns "Hello "+name.
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:
<bean id="theService" class="com.flozano.testbeanoverride.impl.TheServiceBean"
scope="singleton" p:name="Lisa">
</bean>
Affects: 4.0 GA
Reference URL: https://github.com/flozano/spring-override-behavior-changed
Issue Links:
- Allow @Bean to override a dynamically registered bean definition [SPR-10607] #15236 Allow
@Bean
to override a dynamically registered bean definition - Cannot override singleton with scoped proxy [SPR-10744] #15370 Cannot override singleton with scoped proxy
Referenced from: commits 61a3d04
1 votes, 3 watchers