Autowired required a single bean, but 2 were found

  1. 自定注入失敗 發現兩個對象 不能確定注入哪一個
  2. 解決辦法:使用@Qualifier(“XXX”)註解
    @Qualifier(“XXX”) 中的 XX是 Bean 的名稱,所以 @Autowired 和 @Qualifier 結合使用時,自動注入的策略就從 byType 轉變成 byName 了。
  3. 在這裏插入圖片描述
  4. 日誌

***************************
APPLICATION FAILED TO START
***************************

Description:

Field iOnlineUserService in com.after90s.frame.shiro.session.OnlineSessionDAO required a single bean, but 2 were found:
	- userOnlineService: defined in file [D:\workspace-sts\GeneralBackend\target\classes\com\after90s\core\monitor\online\service\OnlineUserServiceImpl.class]
	- IOnlineUserService: defined in file [D:\workspace-sts\GeneralBackend\target\classes\com\after90s\core\monitor\online\service\IOnlineUserService.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章