_bean 的作用域| 学习笔记

简介: 快速学习_bean 的作用域

开发者学堂课程【Java Web 开发系列课程:Spring 框架入门_bean 的作用域】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/538/detail/7339


_bean 的作用域

 

内容介绍:

一、回顾 spring

二、Bean scopesbean的作用域)

三、Table Beanscopes

四、相关代码


一、回顾 spring

spring-桥梁

spring-轻量级, 易学,ioc, aop,事务, 整合框架等 spring- ioc

spring-di

 

二、Bean scopesbean的作用域)

Bean scopes

When you create a bean definition,you create a recipe for creating actual instances of the class defined by that bean definition. The idea that a bean definition is a recipe is important, because it means that. as with a class, you can create many object instances from a single recipe.

You can control not only the various dependencies and configuration values that are to be plugged into an object that is created from a particular bean definition, but also the scope of the objects created from a particular bean definition. This approach is powerful and flexible in that you can choose the scope of the objects you create through confiquration instead of having to bake in the scope of an object at the Java class level. Beans can be defined to be deploved in one of a number of scopes: out of the box,the Spring Framework supports five scopes,three of which are available only if you use a web- aware ApplicationContext.

The following scopes are supported out of the box. You can also create a custom scope.

 

译文:bean 的作用域

创建 bean 定义时,可以创建一个菜谱,用于创建由该 bean 定义的类的实际实例。一个 bean 定义是一个菜谱的想法是很重要的,因为它意味着。

与类一样,您可以从一个菜谱中创建许多对象实例。

您不仅可以控制要插入到从特定 bean 定义创建的对象中的各种依赖项和配置值,还可以控制从特定 bean 定义创建的对象的范围。这种方法功能强大且灵活,因为您可以通过信任选择创建对象的范围,而不必在 Java 类级别的对象范围内进行烘焙。

Bean 可以定义为部署在多个作用域中的一个:开箱即用,Spring 框架支持五个作用域,其中三个只有在使用 Web 感知的 ApplicationContext 时才可用。

支持下列范围还可以创建自定义范围。

 

三、Table Beanscopes

Scope Description  

singleton

(Defaut) Scopes a singe bean definion to a single otject instance per Spring loC container.

prototype

Scopes a single benn definition to any number of object instances

request

Scopes a single bean definition to the lifecycle of a singe HTTP request;that is, each HTTP request has it own instanee of a bean created of the back of a single bean definition.Only valid in the context of a web-aware Spring AppligationContext.

session    

Scopes a singie bean defintion to the lifecyce of an HTTP Session.Only valid in the context of a web-aware Spring ApplicationContext.

Global session  

Scopes a single bean definiton to the lifecycle of a global HTTP Session.Typically only valid when used in a portlet context.Only valid in the context of a web-aware Spring

application  

Scopes a single bean definition to the lifecycle of   a ServlatContext.Only valid in the context of a web-aware Spring ApplicationContext.

 

四、相关代码

http://www.springframework.org/schema/beans/spring-beans.xsd>

北京西三旗"/>

张三丰"/>

相关文章
|
4月前
|
前端开发 Java 开发者
Bean的生命周期和作用域
Bean的生命周期和作用域
|
3月前
|
缓存 前端开发 Java
面试题:说说你对Bean作用域的理解和使用?
面试题:说说你对Bean作用域的理解和使用?
20 0
|
8月前
|
前端开发 Java C++
Bean的作用域
Bean 常见的 6 种作用域
|
8月前
|
Java Spring
案例06 Bean的作用域案例
分别使用singleton和prototype作用域创建Bean实例,比较singleton和prototype作用域的区别。
34 0
|
8月前
|
存储 安全 Java
Bean 的作用域和生命周期
Bean 的作用域和生命周期
46 1
|
8月前
|
开发框架 安全 Java
为什么Spring中每个Bean都要定义作用域
前面的视频中都有提到过Spring Bean的作用域。本期视频呢,我针对Spring Bean作用域做一个详细的解答。关于Spring Bean的作用域,我一共分为两个部分来介绍。首先,介绍Spring Bean作用域的定义,然后,介绍Spring为什么要定义作用域?
50 0
|
8月前
|
XML 安全 Java
Bean作用域和生命周期
Bean作用域和生命周期
|
9月前
|
XML Java 数据格式
一文了解Bean的作用域
了解Bean的作用域
|
9月前
|
XML 存储 Java
Bean的作用域和生命周期(下)
Bean的作用域和生命周期(下)
|
9月前
|
Java Spring 容器
Bean的作用域和生命周期(上)
Bean的作用域和生命周期(上)