美文网首页
Bean的作用域

Bean的作用域

作者: Ar_8be6 | 来源:发表于2019-06-05 22:07 被阅读0次

Bean的作用域:

singleton

当一个bean的作用域为singleton, 那么Spring IoC容器中只会存在一个共享的bean实例,并且所有对bean的请求,只要id与该bean定义相匹配,则只会返回bean的同一实例。

prototype

Prototype作用域的bean会导致在每次对该bean请求(将其注入到另一个bean中,或者以程序的方式调用容器的getBean() 方法)时都会创建一个新的bean实例。根据经验,对所有有状态的bean应该使用prototype作用域,而对无状态的bean则应该使用 singleton作用域

request

在一次HTTP请求中,一个bean定义对应一个实例;即每次HTTP请求将会有各自的bean实例, 它们依据某个bean定义创建而成。该作用 域仅在基于web的Spring ApplicationContext情形下有效。

session

在一个HTTP Session中,一个bean定义对应一个实例。该作用域仅在基于web的Spring ApplicationContext情形下有效。

global session

在一个全局的HTTP Session中,一个bean定义对应一个实例。典型情况下,仅在使用portlet context的时候有效。该作用域仅在基于 web的Spring ApplicationContext情形下有效。

相关文章

  • Spring笔记(二):bean的作用域

    在bean中配置作用域使用属性scope来设置bean的作用域 scope="singleton" 也是bean配...

  • SPRING BEAN的基础

    一、SPRING BEAN的定义: 二、SPRING BEAN的作用域: 作用域例子: your msg :p...

  • Spring_04_Bean的作用域

    Bean的作用域  当在Spring中定义个bean时,你必须声明bean的作用域选项.例如,为了强制Spring...

  • Spring Bean 作用域

    原文 :一文读懂Spring Bean作用域 - RelaxHeart网 Spring Bean的几种作用域 Sp...

  • Bean的作用域

    Bean的作用域: singleton 当一个bean的作用域为singleton,那么Spring IoC容器中...

  • Bean的作用域

    Bean的作用域: singleton 当一个bean的作用域为singleton,那么Spring IoC容器中...

  • Spring

    Spring Bean 作用域 Spring 3 中为 Bean 定义了 5 中作用域分别为 singleton(...

  • spring bean 配置

    bean属性: set注入、构造器注入 beans 作用域 : springBean生命周期1.Bean的作用域可...

  • Spring的作用域和生命周期

    Bean的作用域 Spring 3中为Bean定义了5中作用域,分别为singleton(单例)、prototyp...

  • spring详解(二)

    ③容器中bean的作用域: |作用域|描述||---|---||singleton|单例模式,在整个Spring ...

网友评论

      本文标题:Bean的作用域

      本文链接:https://www.haomeiwen.com/subject/failxctx.html