Skip to content

Improve support for @Configuration class hierarchies [SPR-8187] #12838

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 Apr 4, 2011 · 1 comment
Closed
Assignees
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

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 4, 2011

Chris Beams opened SPR-8187 and commented

Consider the following @Configuration class hierarchy:@Configurationabstract class BaseConfig {
@Bean
Foo foo() {
return new Foo(dataSource());
}

abstract @Bean DataSource dataSource();

}

@Configuration
class ConfigA extends BaseConfig {
@Bean
DataSource dataSource() {
return ...;
}
}

@Configuration
class ConfigB extends BaseConfig {
@Override
@Bean
DataSource dataSource() { return ...; } }
}

It is not currently defined what will happen if all three of these classes are scanned.

Currently the container will parse each @Configuration class and register bean definitions as each are encountered. This means that the DataSource @Bean will be registered three times, and may not be registered in the correct order (e.g. the base class abstract method could be the last encountered and thus the one to override the previous two definitions.

The container should have awareness of @Configuration class hierarchies, and parse/register only the most specific/narrow base class.

Of course, in cases where there are sibling subclasses (same level in the inheritance tree), registration (and overrides) will occur on an as-scanned (or as-registered) basis.


Issue Links:

2 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This doesn't seem to be an issue (anymore) since we're excluding abstract classes from component scanning anyway and have stronger ordering mechanisms now.

Juergen

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: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants