I want to use Spring inside an outdated application.
The core is a class, let it be called LegacyPlugin, which is a kind of insert in the application. The problem is that this class is also a database connector and is used to create many other objects, often using the built-in constructor ...
I want to run ApplicationContext from LegacyPlugin and embed it in ApplicationContext using BeanFactory, for example, to create other objects. Then the code will be rewritten to use setter injection, etc.
I would like to know what is the best way to achieve this. So far I have a working version using BeanFactory that uses ThreadLocal to store a static link to the current plugin, but it seems ugly to me ...
Below is the code I would like:
public class MyPlugin extends LegacyPlugin { public void execute() { ApplicationContext ctx = new ClassPathXmlApplicationContext();
<bean id="plugin" class="my.package.LegacyPluginFactoryBean" /> <bean id="someBean" class="my.package.SomeClass"> <constructor-arg><ref bean="plugin"/></constructor-arg> </bean> <bean id="someOtherBean" class="my.package.SomeOtherClass"> <constructor-arg><ref bean="plugin"/></constructor-arg> </bean>
source share