I'm fairly new to the the Spring and I'm trying to move our legacy code to spring.I'm trying to auto inject all the dependencies by using @Autowired.
My Bean has a factory method as follows:
public static Service getInstance(Registration registration) throws Exception {
Service service = null;
switch(registration.getType()) {
case XServer :
service = new XServer(); break;
case YServer :
service = new YServer(); break;
default :
service = new XServer(); break;
}
service.setRegistration(registration);
return service;
}
But when I use new in the factory method all the dependencies in the new class remains uninitialized. Also if I use appContext.getBean('beanname') it throws following exception:
Requested bean is currently in creation: Is there an unresolvable circular reference?
Can some one help me understand how to do it correct.