File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Spring -> Factory Design Pattern / IOC/DI ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring -> Factory Design Pattern / IOC/DI ?" Watch "Spring -> Factory Design Pattern / IOC/DI ?" New topic

Spring -> Factory Design Pattern / IOC/DI ?

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1432
Spring Bean Container implements Factory Design pattern. but bean container supports IOC/DI. IOC/DI(injects object dependencies whenever it needs) is opposite of Factory design pattern. I do not understand whether Spring supports Factory Design pattern ?
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Yes, if you have a Factory class already you can register it as a bean using the factory-bean and factory-method attributes of the bean tag. If it is a Singleton, you just use the factory-method attribute.

Also Spring has a FactoryBean interface that internally Spring uses a lot to create objects for you. For instance the JndiObjectFactoryBean is a Factory that does JNDI lookups for you so you don't have to write all that boiler plate code. All you have to do is set the jndi name string property, and maybe set, if looking up from a different JVM.

Hope that helps


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
wood burning stoves
subject: Spring -> Factory Design Pattern / IOC/DI ?
jQuery in Action, 3rd edition