1
我現在有代碼佈局,看起來像這樣:注射類似依賴類型不同的策略
interface strategy {}
interface repository {}
class typeOneStrategy implements strategy {
List<repository> repositoryList;
}
class typeTwoStrategy implements strategy {
List<repository> repositoryList;
}
class typeOneRepository implements repository {}
class typeTwoRepository implements repository {}
等。
我想使用Spring的自動裝配來注入typeOneRepository
到typeOneStrategy
但typeTwoRepository
不應該被注入,而僅被注射typeTwoStrategy
。
用Spring的DI可以實現嗎?
實際上,在每個「@ Configuration」中,您可以定義屬於'@ Autowired'的屬性並擁有'@ Qualifier'。 通過使用這些,您可以構建命名bean來定義每個示例的策略輸入。 – bear