Spring作用域

2020-05-17  本文已影响0人  YoungJadeStone

当我们在定义Bean的时候,不仅可以设置它的值,而且可以设置它的作用域(scope)。

scope种类

Spring bean的scope有这么几种:

在多数情况,我们只会使用singleton和prototype两种scope,如果在spring配置文件内未指定scope属性,默认为singleton。Request, session and application只有在the context of a web-aware ApplicationContext(web应用)才有效。

scope设置

可以用@scope来设置。


reference: https://memorynotfound.com/spring-bean-scopes-singleton-vs-prototype/

上一篇 下一篇

猜你喜欢

热点阅读