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
Spring javaconf by default allows to override bean definitions. This could cause hard to find bean name collisions made by mistake in large projects.
To avoid this problem Spring provides GenericApplicationContext.setAllowBeanDefinitionOverriding(false). This helps to resolve name collision problems, but it makes impossible (or very hard) reuse of context configuration with minor adjustments (reuse 100 beans, redefine one or two).
I propose @Bean(override=true) parameter.
With @Bean(override=true) new bean is only registered if there already exists a bean with same name. Previous bean definition is removed during this bean registration.
It is an error if @Bean(override=true) overrides nothing.
allowBeanDefinitionOverriding value is ignored when @Bean(override=true)
@Bean(override=true) works for context similarly to how @Override works for classes and interfaces.
Activity
spring-projects-issues commentedon Jul 13, 2011
Chris Beams commented
Stepan,
See #12637 as well as the other issues labeled with 'bean-visibility-and-overriding'. This is a theme that we'll be addressing in Spring 3.2.
spring-projects-issues commentedon Jul 13, 2011
Stepan Koltsov commented
Thanks, Chris, waiting for 3.2.