11、SmartLifecycle 接口

一、smartLifecycle.start();

1、作用

如果一个 bean 实现了 SmartLifecycle,那么在 SpringBoot 服务启动时,refresh(); 的最后一步 finishRefresh(); 会调用所有实现 SmartLifeCycle 的 bean 的 start(); 前提是 isAutoStartup return true;

2、方法调用时机

SpringApplication.run();
springApplication.run();
abstractApplicationContext.refresh();
abstractApplicationContext.finishRefresh();
defaultLifeCycleProcessor.onRefresh();
defaultLifeCycleProcessor.startBeans(true);

3、defaultLifeCycleProcessor.startBeans(true);

A、找出 beanFactory 中 实现 LifeCycle 的 bean

B、再收集这些 bean 中既实现 SmartLifeCycle,isAutoStartup 又 return true; 的 bean

C、再调用 bean.start();

你可能感兴趣的:(java)