Spring Boot 启动顺序:PostConstruct 和 ApplicationRunner 的执行时机
Spring Boot 应用程序的启动顺序如下:
- 加载配置文件
- 实例化 Spring 容器
- 实例化 Bean
- 注入 Bean
- 调用 'PostConstruct' 方法
- 调用 ApplicationRunner 的 'run' 方法
因此,'PostConstruct' 方法在 Bean 实例化后立即调用,而 ApplicationRunner 的 'run' 方法在 Spring 应用程序完全启动后调用。所以,启动顺序应该是先调用 'PostConstruct' 方法,然后调用 ApplicationRunner 的 'run' 方法。
原文地址: https://www.cveoy.top/t/topic/jpG1 著作权归作者所有。请勿转载和采集!