简体   繁体   中英

Spring dependency injection from webapp to external jars

I am integrating Java Plugin Framework within a Spring based web application (XML-free).

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

I cannot find a way to do this except by using getBean, which I read was not the best practise on this subject.

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.

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

getApplicationContext().getBean(*ClassType*)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM