[英]Spring dependency injection from webapp to external jars
我正在將Java Plugin Framework集成在基於Spring的Web應用程序(無XML)中。
一切都很好,除了插件上下文中的依賴注入
例如,我有一個數據源,我想在插件中使用它,而無需像其他應用程序一樣使用@Autowired返回屬性文件
除了使用getBean以外,我找不到其他方法,我讀過的書並不是該主題的最佳實踐。
我也看過LogicalDoc,但是該項目采用了屬性重載,這對我來說不是正確的解決方案,因為我希望在不進行進一步膠合的情況下就可以進行bean屬性修改。
有誰知道使用這兩種環境的現有開源項目?
由於無法在插件中注入依賴關系,我最終在所有插件的母類中添加了以下方法
public void setContext(ApplicationContextProvider a_ctx) {
m_theContext = a_ctx;
}
public ApplicationContext getApplicationContext() {
return m_theContext.getApplicationContext();
}
然后從插件中獲取bean
getApplicationContext().getBean(*ClassType*)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.