Scope有两两个属性在这里给大家介绍一下:

Spring常用配置之Scope:每次调用会创建一个新的实例

Spring常用配置之Scope:一个Spring容器只有一个Bean的实例,此为Spring的默认配置,全容器只共享一个实例

举一个例子给大家介绍一下:

1、编写singleton的Bean

Spring常用配置之Scope

2、编写Prototype的bean

Spring常用配置之Scope

3、配置类:

Spring常用配置之Scope

运行:

Spring常用配置之Scope


结果;

Spring常用配置之Scope

相关文章:

  • 2021-06-22
  • 2022-12-23
  • 2021-10-15
  • 2021-06-08
  • 2022-12-23
  • 2021-07-10
  • 2021-07-25
  • 2021-06-13
猜你喜欢
  • 2022-02-18
  • 2021-04-08
  • 2021-11-03
  • 2021-11-24
  • 2022-12-23
  • 2021-07-29
  • 2022-01-20
相关资源
相似解决方案