当前位置: 首页 > news >正文

Bean Scopes

Bean Scopes

官方文档

Scope Description
singleton (Default) Scopes a single bean definition to a single object instance for each Spring IoC container.
prototype Scopes a single bean definition to any number of object instances.
request Scopes a single bean definition to the lifecycle of a single HTTP request. That is, each HTTP request has its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring .ApplicationContext
session Scopes a single bean definition to the lifecycle of an HTTP . Only valid in the context of a web-aware Spring .Session``ApplicationContext
application Scopes a single bean definition to the lifecycle of a . Only valid in the context of a web-aware Spring .ServletContext``ApplicationContext
websocket Scopes a single bean definition to the lifecycle of a . Only valid in the context of a web-aware Spring .WebSocket``ApplicationContext

1.单例模式 (默认机制是单例)

辛格尔顿

代码实例(用的之前的beans.xml文件)

image-20260317164457061

 com.wjj.pojo.Student student =(Student) context.getBean("student");com.wjj.pojo.Student student2 =(Student) context.getBean("student");System.out.println(student.hashCode());System.out.println(student2.hashCode());System.out.println(student.equals(student2));

2.圆形模式 (xml文件改动)

prototype

image-20260317165203901

<bean id="student" class="com.wjj.pojo.Student" scope="prototype">
http://www.jsqmd.com/news/492363/

相关文章:

  • 跨平台开发必看:Windows/Linux下struct语法差异全解析(附GCC兼容方案)
  • AWPortrait-Z保姆级教程:从安装到生成第一张美颜照片
  • 车联网仿真进阶:如何用SUMO生成逼真交通流数据(含Python脚本优化技巧)
  • Qwen3-14b_int4_awq惊艳效果:输入‘画一个架构图:用户登录流程’生成PlantUML代码
  • 基于天空星HC32F4A0的AS608光学指纹模块驱动移植与功能实现
  • 老旧设备复活:用OpenCore Legacy Patcher让2015年前Mac支持最新系统
  • 海森矩阵可视化教程:用Python画出二阶偏导数的几何意义
  • LaTeX新手必看:解决参考文献编译报错‘Missing \item‘的完整指南
  • PyTorch 2.8 多GPU支持实测:低成本验证分布式训练
  • AI艺术创作入门:万象熔炉·丹青幻境部署与初体验
  • 零基础玩转通义千问2.5:7B模型一键部署与可视化界面体验
  • 零基础入门:借助快马生成交互式MathType安装教学应用
  • Qt工具栏美化指南:如何用QAction打造专业级UI(含图标资源管理技巧)
  • Phi-3-vision-128k-instruct应用案例:智慧农业病虫害图谱识别与防治建议
  • GTE文本向量-large部署教程:GPU显存占用监控(nvidia-smi)与batch_size调优技巧
  • ESP32 IDF项目结构详解:从零开始搭建你的第一个S3芯片项目(V5.4.0版)
  • Kook Zimage真实幻想Turbo升级体验:24G显存流畅运行1024高清图
  • Qwen3-14B实际应用:某IoT厂商用其解析设备协议文档并生成SDK注释
  • Unity安卓模块安装异常排查:手动清理残留配置与模块修复指南
  • C++异常处理:从入门到精通
  • Nano-Banana Studio惊艳效果:高对比度复古画报风牛仔外套拆解
  • 前端工程化实战:项目亮点与技术难点的深度解析与解决方案
  • Qwen-Turbo-BF16效果对比:BF16在复杂多物体场景中的边缘锐度与结构保持
  • 文墨共鸣大模型与数据库联动实战:基于MySQL的知识库问答系统构建
  • Qwen3-14B惊艳案例:仅输入‘写一个Flask接口接收JSON并返回校验结果’即生成完整可运行代码
  • HTML入门基础笔记
  • Navicat太贵?这3款免费数据库工具帮你省下每一分钱(附详细配置指南)
  • Idea高效开发秘籍:从快捷键到性能优化全解析
  • 如何通过蓝牙键鼠实现跨设备无缝切换?
  • 2026陕西铝单板应用白皮书商业门头装饰篇 - 优质品牌商家