Spring Bean Scope

Bean Scope

When defining a bean in Spring, you must declare the scope options of the bean. For example, to force Spring to generate a new bean instance every time it needs to, you should declare the attribute of the bean’s scope as prototype. Similarly, if you want Spring to return the same bean instance every time you need it, you should declare the scope property of the bean as singleton.
The Spring framework supports the following five scopes. If you use web aware ApplicationContext, three of them are available.

Scope describe
singleton There is only one bean instance in the spring IoC container. The bean exists as a single instance.
prototype Every time a bean is called from the container, a new instance is returned, that is, every time getBean() is called, it is equivalent to executing newXxxBean()
request Each HTTP request will create a new bean. This scope is only applicable to the WebApplicationContext environment
session The same HTTP session shares a bean, and different sessions use different beans, which is only applicable to the WebApplicationContext environment
global-session It is generally used in the portlet application environment, which is only applicable to the WebApplicationContext environment

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-04 13:42:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-04 13:42:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-04 13:42:01       87 阅读
  4. Python语言-面向对象

    2024-05-04 13:42:01       96 阅读

热门阅读

  1. 网络工程师----第十九天:

    2024-05-04 13:42:01       37 阅读
  2. Python爬虫:线程,进程与协程

    2024-05-04 13:42:01       34 阅读
  3. HttpUtil的定义

    2024-05-04 13:42:01       31 阅读
  4. 【代码随想录】day50

    2024-05-04 13:42:01       34 阅读
  5. Redis rehash 相关问题

    2024-05-04 13:42:01       37 阅读
  6. File 文件搜索,啤酒问题,删除非空文件夹

    2024-05-04 13:42:01       34 阅读
  7. db2常用命令大全(高级篇)

    2024-05-04 13:42:01       32 阅读
  8. 机车 - 教你学摩托车

    2024-05-04 13:42:01       27 阅读
  9. Linux之sed命令(包含MacOS使用方法)

    2024-05-04 13:42:01       37 阅读