Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jul 12, 2011 · 2 comments
Closed

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

spring-projects-issues opened this issue Jul 12, 2011 · 2 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 12, 2011

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:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented 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
Copy link
Collaborator Author

Stepan Koltsov commented

Thanks, Chris, waiting for 3.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant