You can't "DI existing service beans with those objects" with Spring (not out of the box, that is). If you refresh the context, you will create new instances of all the beans. You may be able to organize the context into sub-contexts and only refresh those that may be interested by the change, to limit unnecessary reloading. However, if service beans are stateful, or are registered somewhere (JMS listeners, web service endpoints, ...), this can be a problem.
I think you can use factory beans and/or static factory methods in a way that allows you to reconfigure your existing (singleton) service beans. Roughly sketched:
Code:
public class Foo {
...
ApplicationContext baseContext = ...
GenericApplicationContext newContext = new GenericApplicationContext();
...load xml files with DAOs and whatever...
newContext.registerSingleton("myServiceBean-original", baseContext.getBean("myServiceBean"));
GenericBeanDefinition myServiceBeanFactory = new GenericBeanDefinition();
myServiceBeanFactory.setBeanClass(Foo.class);
myServiceBeanFactory.setFactoryMethodName("identity");
myServiceBeanFactory.setConstructorArgumentValues(...ref="myServiceBean-original"...);
myServiceBeanFactory.setPropertyValues(...user-defined properties...);
...
public static Object identity(Object o) { return o; } //Dummy factory-method
...
}
I'm not sure if autowiring will work in such a scenario: I'll do some tests.