Spring 之 Bean 的 Scope

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_29689487/article/details/81976167

Bean 的 Scope

Scope 描述的是 Spring 容器如何新建 Bean  的实例的. Spring 的 Scope 有以下几种,通过 @Scope 注解来实现.

  1. Singleton: 一个 Spring 容器中只有一个 Bena 的实例,此为 Spring 的默认配置,全容器共享一个实例.
  2. Prototype:  每次使用新建一个 Bean 的实例.
  3. Request: Web 项目中,给每一个 HTTP request 新建一个 Bean 实例.
  4. Session : Web 项目中,给每一个 HTTP session 新建一个 Bean 实例.
  5. GlobalSession:  这个只在 portal 应用中有用,给每一个 global HTTP session 新建一个 Bean  实例.
  6. StepScope:  只有在 Spring Batch  中使用.

猜你喜欢

转载自blog.csdn.net/qq_29689487/article/details/81976167