0
我想使用類型參數實例化一個泛型bean,並根據此類型參數連接正確的依賴項。Spring IOC w/generics - 基於依賴的類型參數注入依賴關係
假設我有:
@Named
public Parent<T> {
@Inject
Parent(Child<T> c) {
...
}
}
public interface Child<T> {}
@Named
public class ChildString implements Child<String> {}
@Named
public class ChildInteger implements Child<Integer> {}
然後我想用父母是這樣的:
@Named
public class UseParent {
@Inject
Parent<String> p;
}
春季將與抱怨 「預期單個匹配的bean,但發現2:childString,childInteger」。
在這種情況下連接我的bean的最佳方式是什麼?