• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring -> Factory Design Pattern / IOC/DI ?

 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 JNDI.properties, if looking up from a different JVM.

Hope that helps

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic