The only other detail to cover is how your legacy service registers itself so that the Spring configuration can be applied to it. You accomplish this by using the oranjestad class SpringConfigurationBridge, which is called by the service after it has been initialized:
import oranjestad.spring.bootstrap.SpringConfigurationBridge;
public class MyLegacyService extends SomePreIOC_AbstractService {
Pojo1 pojo1;
Pojo2 pojo2;
public void setPojo1(Pojo1 p1) {
pojo1 = p1;
}
public void setPojo2(Pojo2 p2) {
pojo2 = p2;
}
public MyLegacyService(String serviceName) {
super(serviceName);
}
// some pre-dependency injection configure method
// called by the legacy framework.
public void configure(ServiceConfig config) {
super.configure(config);
SpringConfigurationBridge.
configure(this, "some.service");
}
}
With the external bean approach, you have much greater flexibility with services that get created in an intertwined fashion. External beans do the following for your legacy system:
- Handle all combinations of the legacy services starting before or after Spring
- Extend dependency injection to your legacy system
- Add some automatic annotation-based capabilities such as Spring's JMX annotations for creating MBeans to work with your legacy service
This approach can greatly increase the adoption of Spring into a legacy framework by eliminating ugly bean lookups from the legacy service as well as by moving configuration from the legacy system to Spring.