起因:在写一个Springboot项目时,队友将项目加载方式改为
lazy-init
,理由是能加快重启的速度,但是导致了Bug
Spring在Bean初始化阶段会对所有继承了ApplicationContextAware
接口的类注入ApplicationContext
但是如果设置了lazy-init
,bean加载顺序变了,setApplicationContext
就不执行了
起因:在写一个Springboot项目时,队友将项目加载方式改为
lazy-init
,理由是能加快重启的速度,但是导致了Bug
Spring在Bean初始化阶段会对所有继承了ApplicationContextAware
接口的类注入ApplicationContext
但是如果设置了lazy-init
,bean加载顺序变了,setApplicationContext
就不执行了
Author: qing-wq
Permalink: https://qing-wq.github.io/2023/11/01/Spring%20Lazy-init%20%E8%B8%A9%E5%9D%91%E8%AE%B0%E5%BD%95/
License: Copyright (c) 2019 CC-BY-NC-4.0 LICENSE