Normally if I want to implement a factory pattern I will do it like this.
public class CustomFactory(){
// pay attention: parameter is not a string
public MyService getMyService(Object obj){
/* depending on different combinations of fields in an obj the return
type will be MyServiceOne, MyServiceTwo, MyServiceThree
*/
}
}
MyServiceOne, MyServiceTwo, MyServiceThree are implementations of the interface MyService.
That will work perfectly fine. But the issue is that I would like to have my objects instanciated by Spring container.
I've looked through some examples and I know how to make Spring container create my objects depending on a string.
The queston is: can I include implemenations of objects by Spring Container in this example or should I make all my manipulations with Object obj in some other place and write a method public MyService getMyService(String string) in my CumtomFactory?
Well what do you think about following way? :
EDIT :
Answers to your questions in comment :
--> Yes definitely, you are getting those beans from Spring.
--> See below xml :
--> See getMyService() method in above code, it is updated.