基于Xml方式Bean的配置-Bean的延时加载

SpringBean的配置详解

  • Bean的延时加载
    • 当lazy-init设置为true时为延时加载,也就是当Spring容器创建的时候,不会立即创建Bean实例,等待用到时再创建Bean实例并储存到单例池中,后续使用该Bean时直接从单例池中获取即可,本质上该Bean还是单例(singleton)
      *

      java 复制代码
          <bean id="userService" name="aaa,bbb" class="com.example.Service.Impl.UserServiceImpl" lazy-init="true">
    • 但未设置时

      XML 复制代码
          <bean id="userService" name="aaa,bbb" class="com.example.Service.Impl.UserServiceImpl">
      • 对上述代码进行调试,当创建Spring容器时,就会立即创建Bean实例。

    • 设置lazy-init=true
      *

      XML 复制代码
          <bean id="userService" name="aaa,bbb" class="com.example.Service.Impl.UserServiceImpl" lazy-init="true">
      • 当调用才会创建Bean实例

相关推荐
ps酷教程1 小时前
Jackson 解决没有无参构造函数的反序列化问题
java
NiceCloud喜云1 小时前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
AI玫瑰助手2 小时前
Python函数:默认参数的定义与注意事项
开发语言·python·信息可视化
油炸自行车2 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
肩上风骋2 小时前
C++14特性
开发语言·c++·c++14特性
_日拱一卒2 小时前
LeetCode:994腐烂的橘子
java·数据结构·算法·leetcode·深度优先
隔窗听雨眠2 小时前
Nginx网关响应慢排查手记
java·服务器·nginx
智慧物业老杨3 小时前
智慧物业合同周期管理系统:从风险预警到智能交接的全流程数智化落地方案
java·人工智能·python
源码宝3 小时前
MES系统源码:Java8 + SpringBoot2.7 + MySQL8 + Redis,后端源码清爽易扩展
java·后端·源码·springboot·mes系统·源码二开·mes源码
JAVA社区3 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展