什么是java中的惰性初始化,惰性初始化的默认行为

I am beginner to spring, ESP Inversion of control. I was puzzled understanding the difference between the following

To my understanding : lazy-init=false creates the bean at the startup and lazy-init=true doesn't create a bean at the startup rather creates the bean upon request for a particular bean.

Correct me here, If my interpretation is wrong.

what exactly the default behavior of lazy-init is? How would it instantiate?

解决方案

The default behaviour is false:

By default, ApplicationContext implementations eagerly create and

configure all singleton beans as part of the initialization process.

Generally, this pre-instantiation is desirable, because errors in the

configuration or surrounding environment are discovered immediately,

as opposed to hours or even days later. When this behavior is not

desirable, you can prevent pre-instantiation of a singleton bean by

marking the bean definition as lazy-initialized. A lazy-initialized

bean tells the IoC container to create a bean instance when it is

first requested, rather than at startup.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值