I am new Springs. In Bean tag I found factory-method and factory-bean Attributes. What is the difference between factory-method and factory-bean?
I am using factory-meth
factory-method:
As everyone has already explained, factory-method is used to tell the spring to use the factory method to instantiate the object.
Note: static method is mandatory else throws an exception.
factory-bean:
When there is no static method and still you want to create the object using non static method, here is the trick can be done using factory-bean:
Note: no class attribute required in the above spring definition.
Class:
public class ServiceFactory {
public static ServiceFactory getServiceFacrotyWithStaticMethod(){
return new ServiceFactory();
}
public SdCard getInstanceWithOutStaticMethod(){
return new AdaptorSlot("laptop");
}
}