[英]Spring dependency injection from webapp to external jars
I am integrating Java Plugin Framework within a Spring based web application (XML-free). 我正在将Java Plugin Framework集成在基于Spring的Web应用程序(无XML)中。
Everything is fine, except for the dependency injection in plugin context 一切都很好,除了插件上下文中的依赖注入
For instance I have a data source I would like to use in a plugin without having to go back to property files by using @Autowired like for the rest of the application 例如,我有一个数据源,我想在插件中使用它,而无需像其他应用程序一样使用@Autowired返回属性文件
I cannot find a way to do this except by using getBean, which I read was not the best practise on this subject. 除了使用getBean以外,我找不到其他方法,我读过的书并不是该主题的最佳实践。
I also had a look at LogicalDoc but this project resorts to properties reloading which is not the correct solution for me as I want beans attributes modifications to be available without further glue. 我也看过LogicalDoc,但是该项目采用了属性重载,这对我来说不是正确的解决方案,因为我希望在不进行进一步胶合的情况下就可以进行bean属性修改。
Does anyone know of an existing open source project where both these environment are used ? 有谁知道使用这两种环境的现有开源项目?
Not being able to inject dependencies in plugins, I finally added the following methods to mother class of all plugins 由于无法在插件中注入依赖关系,我最终在所有插件的母类中添加了以下方法
public void setContext(ApplicationContextProvider a_ctx) {
m_theContext = a_ctx;
}
public ApplicationContext getApplicationContext() {
return m_theContext.getApplicationContext();
}
And retreive the beans from within the plugin by 然后从插件中获取bean
getApplicationContext().getBean(*ClassType*)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.