這裏需要一些幫助。 在我們的項目中,我們使用XML和註釋配置(春季4.1) 最近,我遇到了以下任務:在春季將原型列表注入Singleton bean中
我的範圍原型豆名單,他們都實現了相同的接口。
另外我有一個singleton bean有execute
方法。在該方法內部,bean應該訪問這些原型bean的列表。
每次執行'execute'方法時,我都想要訪問這些原型bean的不同實例)。 在單例中,我沒有提前知道bean的全部列表,所以我只需@Autowire
整個集合,以便應用程序上下文中已知的每個bean實現都將被加載。
interface SomeInterface {
}
class PrototypeBean1 implements SomeInterface {
...
}
class PrototypeBean2 implements SomeInterface {
...
}
class MySingletonBean {
@Autowire (????)
List<SomeInterface> allPrototypeBeansLoadedIntoTheApplicationContext;
public void execute() {
// this one is called many times,
// so I would like to get different lists of
//"allPrototypeBeansLoadedIntoTheApplicationContext"
// with different actuals bean upon every invocation
// how do I achieve this???
}
}
所以我的問題是:什麼是最乾淨的方式來實現這一目標?理想情況下,我想得到一個完全從彈簧接口解耦的解決方案(如注入ApplicationContext/BeanFactory的東西) 我不介意在這裏使用Aop(性能不是那麼重要),但我無法真正包裹我的頭一個乾淨的春天解答。所以任何幫助將不勝感激。
在此先感謝