开发者学堂课程【Java Web 开发系列课程:Spring 框架入门:_bean 的作用域】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/538/detail/7339
_bean 的作用域
内容介绍:
一、回顾 spring
二、Bean scopes(bean的作用域)
三、Table Beanscopes
四、相关代码
一、回顾 spring
spring-桥梁
spring-轻量级, 易学,ioc, aop,事务, 整合框架等 spring- ioc
spring-di
二、Bean scopes(bean的作用域)
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>
北京西三旗"/>
张三丰"/>