Saturday 19 March 2011

Spring : factory-method

Consider a java class containing no setter or constructor, but a static method to return its instance.

public class ClientService {    
private static ClientService clientService = new ClientService();
private ClientService() {}

public static ClientService createInstance() {
return clientService;
}
}


So to creating this bean we use factory-method attribute on bean.


<bean id="clientService" class="ex2.ClientService" factory-method="createInstance" />


Case when factory-method as argument as well

No comments:

Post a Comment