3.springbean的作用域

https://baijiahao.baidu.com/s?id=1610298792072480906&wfr=spider&for=pc

https://blog.csdn.net/weixin_42223248/article/details/113852199

一共是5种作用域,低版本的是下面两种

作用域的种类
Spring 容器在初始化一个 Bean 的实例时,同时会指定该实例的作用域。Spring3 为 Bean 定义了五种作用域,具体如下。

1)singleton

单例模式,使用 singleton 定义的 Bean 在 Spring 容器中只有一个实例,这也是 Bean 默认的作用域。

2)prototype

原型模式,每次通过 Spring 容器获取 prototype 定义的 Bean 时,容器都将创建一个新的 Bean 实例。
e/details/126259496

 

Spring对每个bean提供了一个scope属性来表示该bean的作用域。它是bean的生命周期。例如,一个scope为singleton的bean,在第一次被注入时,会创建为一个单例对象,该对象会一直被复用到应用结束。

 

posted on 2023-04-26 11:03  companion  阅读(13)  评论(0编辑  收藏  举报