This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Spring and the fly likes How to inject a factory through Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to inject a factory through Spring" Watch "How to inject a factory through Spring" New topic
Author

How to inject a factory through Spring

Anshul Chandra Saxena
Greenhorn

Joined: Sep 10, 2009
Posts: 14
Hi

I have a main class, that receives an action from the jsp. On the basis of action value i need to invoke the correct service. I have adopted the Abstract Factory Pattern, wherein on the basis of action value, the correct service is invoked. My only problem is how to inject this factory into the main class using Spring.

Can anyone please let me know, how to do this.

thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

There are Factory classes that you can create in Spring that can create instances for that class to inject. All you have to do is implement the FactoryBean interface. This way your instances can also be set to prototype, so that you get a new instance each time.

http://www.google.com/url?sa=t&source=web&ct=res&cd=1&url=http%3A%2F%2Fstatic.springsource.org%2Fspring%2Fdocs%2F2.5.x%2Fapi%2Forg%2Fspringframework%2Fbeans%2Ffactory%2FFactoryBean.html&ei=RWG2Som1J4qasgPpgsTRDA&usg=AFQjCNEKWO-LNJbQPEIRJbpQrAe7k_F5OQ

http://www.google.com/url?sa=t&source=web&ct=res&cd=3&url=http%3A%2F%2Fblog.arendsen.net%2Findex.php%2F2005%2F07%2F03%2Fusing-factorybeans-to-create-the-uncreatable%2F&ei=RWG2Som1J4qasgPpgsTRDA&usg=AFQjCNG66JLAd9rI0WRDLwkxxbBf7mtaPA


Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to inject a factory through Spring
 
Similar Threads
How to inject EntityManager via setter in spring
Spring core container is the basis for complete Spring framework?
What to choose, daoFactory or a SpringUtil from ZK?
spring wont inject the entitymanager
Injection - instance variable