Skip to content

@Bean(override=true) [SPR-8528] #13172

Closed
Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions