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

前端 未结 6 2035
小鲜肉
小鲜肉 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:37

    A FactoryBean is used as factory for other beans/objects. It cannot be used as bean itself.

    The factory-method can be used to define the method that should be used to create this bean (instead of calling the constructor). A bean with a factory method can be used as a bean itself.

    Spring can create bean instances using many different factory types. This is useful if you want to integrate libraries/legacy classes that are bound to a particular type.

提交回复
热议问题