Skip to content
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

Doc: MessageSource is identified by bean name, this is very confusing [SPR-4321] #9000

Closed
spring-projects-issues opened this issue Jan 10, 2008 · 3 comments
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

Alef Arendsen opened SPR-4321 and commented

MessageSource is (AFAIK) one of the few beans that are NOT automatically picked up by type by the application context. In the past ViewResolver and HandlerMapping were picked up by id too, but not anymore.

Can we change MessageSource to by picked up by type too instead of by name? It's very confusing to people right now I just learned...


Affects: 2.0.8, 2.5.1

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Point taken, Alef. However, there are actually quite a few such beans left: e.g. "loadTimeWeaver", "applicationEventMulticaster" or also "viewNameTranslator" in a DispatcherServlet...

The basic rule is that bean names are used wherever there must be only one such bean from a delegation point of view. In contrast to that, by-type detection is used wherever any number of beans of such a type are supported.

This allows the single-bean case to define e.g. a custom "messageSource" entry point bean which in turn delegates to backend beans of type MessageSource but according to custom rules.

MessageSource delegation follows an inheritance rule at present, which is why there needs to be exactly one per ApplicationContext. Short of redefining that rule, by-type detection of MessageSources would arguably lead to messy semantics...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Jon Osborn commented

I agree. Maybe the issue is really lack of clear documentation on which beans are loaded by name and which by type?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
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