What is the difference between spring factory-method and factory-bean?

前端 未结 6 2014
小鲜肉
小鲜肉 2021-02-02 10:28

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

6条回答
  •  借酒劲吻你
    2021-02-02 10:53

    in spring we use factory-method because in java predefine class and some use define class are there the are not provide direct to create the object of other class there are some abstract class we can not create object but in side the class there are method are there like Calendar class we can not create the object of Calendar class

    Calendar cal = new Calendar(); 
    

    it is wrong on that thime its give error but it is provide the method getInstance() we can call the method and we can instance the class

    Example:

    Calendar cal=Calendar.getInstance();  
    

    it is correct on that time we use factory method in the spring example:

    
    

提交回复
热议问题