I need to implement factory pattern in spring, until now i was using spring config file. The issue is that i have Dao Interface and have two concrete implementation one is solr and the othe is mockDao
I have put the snippet below for my config file and it works fine, what i wanted was how to use the ObjectFactoryCreatingFactoryBean with annotation
As seen below i have a daoFactory class as singleton with map defined with One key referencing to mockDaoFactory which is "ObjectFactoryCreatingFactoryBean" and its target is hooked up to the concreate implementation. this gives me flexibility for make Daofactory return different implementaion of concreate classes.
i am sure this kind of map entries can be defined using annotation too, can someone please let me know about any tutorial etc...
Assuming that both mockDaoImpl and mockDaoSolr implement the same interface, you could use the following autowiring to set all concrete implementations in a Map. The problem is that the Map's key will be the name of the bean.
The Main class execution will produce something like :
Thanks for the reply
the other thing i wanted to ask was how to tell the DaoFactory to be singleton. In the config file we can always specify the scope as singleton or prototype, but when we use autowire how to we tell spring to create singleton beans or not.
Thanks for your suggestion.
the only concern i have in your prescribed example, you are setting the map with concrete dao implementaion class, but the issue i that, map will have reference to only one object of either solrDaoImpl or mockDaoImpl.
the issue is that how can i get a new Dao concrete instance whenever i call DaoFactory.getconcrete class implementation.
the previous example i quoted was that my dao factory was wired to objectProxyFactoryBean which will give new instances of concrete implementation.
Hope i am making sense