I have a singleton that has spring introduced by Tao (simplified below):
public class MyService<T> implements Service<T> { private final Map<String, T> objects; private static MyService instance; MyDao myDao; public void set MyDao(MyDao myDao) { this. myDao = myDao; } private MyService() { this.objects = Collections.synchronizedMap(new HashMap<String, T>());
My spring configurator will probably look like this:
<bean id="service" class="MyService" factory-method="getInstance"/>
But this will create an instance of MyService at startup.
Is there a programmatic way to inject MyDao dependencies into MyService but not have spring manage MyService?
Basically, I want to be able to do this from my code:
MyService.getInstance().doSomething();
having spring for entering MyDao for me.
spring dependency-injection singleton
Langali
source share