_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>

北京西三旗"/>

张三丰"/>

相关文章
在虚拟机上EFI启动模式安装WIN10
工具:虚拟机(vmware12),WIN10原版(msdn上下载的) 安装步骤:   前面虚拟机设置的图没截好,就不放了,基本都一样的,老版本的vmware可能没有WIN10选项,选WIN7应该也是可以的。
3762 0
|
2天前
|
数据采集 人工智能 安全
|
11天前
|
云安全 监控 安全
|
3天前
|
自然语言处理 API
万相 Wan2.6 全新升级发布!人人都能当导演的时代来了
通义万相2.6全新升级,支持文生图、图生视频、文生视频,打造电影级创作体验。智能分镜、角色扮演、音画同步,让创意一键成片,大众也能轻松制作高质量短视频。
1020 151
|
3天前
|
编解码 人工智能 机器人
通义万相2.6,模型使用指南
智能分镜 | 多镜头叙事 | 支持15秒视频生成 | 高品质声音生成 | 多人稳定对话
|
16天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
1716 9
|
8天前
|
人工智能 自然语言处理 API
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸
一句话生成拓扑图!next-ai-draw-io 结合 AI 与 Draw.io,通过自然语言秒出架构图,支持私有部署、免费大模型接口,彻底解放生产力,绘图效率直接爆炸。
658 152
|
10天前
|
人工智能 安全 前端开发
AgentScope Java v1.0 发布,让 Java 开发者轻松构建企业级 Agentic 应用
AgentScope 重磅发布 Java 版本,拥抱企业开发主流技术栈。
622 12