Spring bean scope. Singleton and Prototype

前端 未结 3 723
野趣味
野趣味 2021-01-18 01:45

Suppose two classes ClassA and ClassB. Lets suppose ClassB is dependent on ClassA. On configuration file, if we define scope of ClassA to be singleton and that of ClassB to

3条回答
  •  -上瘾入骨i
    2021-01-18 02:18

    what happens to instance of ClassB each time we create a bean instance of ClassA?

    Nothing, if ClassA is singleton it will be instantiated only once.

    Will the same ClassB instance gets returned or new instance is created each time instance of ClassA is returned?

    Different instances, since it's a prototype bean. But since ClassA is singleton it will be instanciated the same way every time.(depends on your relation between these classes that you mentioned)

提交回复
热议问题