Ignore identical BeanDefinition
registration when allowBeanDefinitionOverriding
is false
#27978
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: declined
A suggestion or change that we don't feel we should currently apply
type: enhancement
A general enhancement
Affects: 2.5.2 - 5.3, Spring Boot 2.1+
Calling
DefaultListableBeanFactory.registerBeanDefinition()
twice with the same bean name and same or equalBeanDefinition
object results in an exception ifallowBeanDefinitionOverriding
was set tofalse
(as is the default in Spring Boot 2.1+).The javadoc for
DefaultListableBeanFactory.setAllowBeanDefinitionOverriding
specifically defines (emphasis is mine):Practically, this makes splitting a monolith into modules and libraries a lot harder as it bans common bean definitions due to recursive imports, e.g.:
@Import(DbConfig.class)
.@Import(DbConfig.class)
.allowBeanDefinitionOverriding=false
.Allowing for silent-ignore of identical definitions will ease transitions from "one large context" to smaller modules that can be self-descriptive in their dependencies.
This behavior was introduced in #9052.
The text was updated successfully, but these errors were encountered: