Emerson Farrugia opened SPR-10808 and commented
I've hit an issue where a single component scan was finding two @Beans with the same name. The beans weren't intentionally named the same, it was just an oversight. The container initialised one bean and ignored the other, logging at info instead of warn. The logging level is the first problem, since logging at info makes it much more likely the message is missed. The second problem is that the ignored bean was explicitly marked as @Primary. I've attached files with an example.
As far as I can tell, there's no way to control which bean gets picked in this situation. @Order on the @Configuration doesn't help.
In terms of fixes, I suggest the info message gets changed to warning. I'd personally even go one further. Given the functionality of @Profile, @Primary, and that autowiring by type is encouraged, does bean overriding still make sense in 3.1+.x? @Profile and @Primary give us a deterministic way of controlling autowire candidates. In contrast, quiet non-deterministic overrides by name seem too fragile to fit.
Affects: 3.2.3
Attachments:
Issue Links:
2 votes, 7 watchers
Emerson Farrugia opened SPR-10808 and commented
I've hit an issue where a single component scan was finding two
@Beanswith the same name. The beans weren't intentionally named the same, it was just an oversight. The container initialised one bean and ignored the other, logging at info instead of warn. The logging level is the first problem, since logging at info makes it much more likely the message is missed. The second problem is that the ignored bean was explicitly marked as@Primary. I've attached files with an example.As far as I can tell, there's no way to control which bean gets picked in this situation.
@Orderon the@Configurationdoesn't help.In terms of fixes, I suggest the info message gets changed to warning. I'd personally even go one further. Given the functionality of
@Profile,@Primary, and that autowiring by type is encouraged, does bean overriding still make sense in 3.1+.x?@Profileand@Primarygive us a deterministic way of controlling autowire candidates. In contrast, quiet non-deterministic overrides by name seem too fragile to fit.Affects: 3.2.3
Attachments:
Issue Links:
@Beanmethods to override definitions in XML@Beanto override a dynamically registered bean definition@Primaryannotation is not working for beans with the same name@Primaryannotation not working when overriding bean definition with classpath scanning2 votes, 7 watchers