Two beans with the same name results in ConflictingBeanDefinitionException despite using @Primary

孤者浪人 提交于 2019-12-05 21:44:34

@Primary has no relation to bean names. The javadoc states

Indicates that a bean should be given preference when multiple candidates are qualified to autowire a single-valued dependency.

This only applies to a context containing two beans of some type A where a bean of type B requires an A to be injected. The A bean annotated with @Primary will have priority.

Bean ids/names for a given type must be unique. (Bean definitions with the same name can overwrite each other for the same bean type. For example, this would happen if you component scanned a class annotated with @Component but also provided a @Bean method for that same type.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!