Tags

links:
http://blog.springsource.org/2011/08/09/whats-a-factorybean/
http://blog.springsource.org/2011/08/10/beyond-the-factorybean/

summary:
– feel like a way around of constructor-centric spring container limitation before 3.0
– spring 3.0 and above not recommend this approach (?), kinda phased out by JavaConfig
– JavaConfig you can apply the Builder pattern basically give similar result from FactoryBean without the complexity

– FactoryBean is another class to create the actual class you really after
– a pattern to encapsulate interesting object construction logic in a class
– help Spring construct objects that it couldn’t easily construct itself, e.g. JNDI?
– a FactoryBean does is encode construction logic in a unique way, then there’s no reason that couldn’t be done inside a Java configuration method

public class ClientServiceFactory {
  ....
  public ClientService getNewInstance() {
      .... 
  }
}

<bean id="clientServiceFactory" class="example.ClientServiceFactory"/>

<bean id="clientService" factory-bean="clientServiceFactory" factory-method="getNewInstance"/>
Advertisements