問題
@Autowired注入一個接口, 一個接口下有多個實現類時, 自動注入接口造成idea檢測到錯誤
Could not autowire. There is more than one bean of 'UserDetailsService' type.

圖1 問題
原因
一個接口下有多個實現類, idea不知道該注入哪個類實現這個接口, 必須指定實現類的具體名字
解決
在字段上使用@Qualifier搭配@Autowired進行構造方法注入
首先, 為service層的實現類指定名字

圖2 為@Service指定名字
使用構造器注入, 在構造參數的字段上使用Qualifier注解

圖2 使用@Qualifier注解