@Bean(override=true) [SPR-8528] #13172
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: duplicate
A duplicate of another issue
type: enhancement
A general enhancement
Stepan Koltsov opened SPR-8528 and commented
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.Affects: 3.1 M2
Issue Links:
The text was updated successfully, but these errors were encountered: