Spring Boot 应用程序的启动顺序如下:

  1. 加载配置文件
  2. 实例化 Spring 容器
  3. 实例化 Bean
  4. 注入 Bean
  5. 调用 'PostConstruct' 方法
  6. 调用 ApplicationRunner 的 'run' 方法

因此,'PostConstruct' 方法在 Bean 实例化后立即调用,而 ApplicationRunner 的 'run' 方法在 Spring 应用程序完全启动后调用。所以,启动顺序应该是先调用 'PostConstruct' 方法,然后调用 ApplicationRunner 的 'run' 方法。

Spring Boot 启动顺序:PostConstruct 和 ApplicationRunner 的执行时机

原文地址: https://www.cveoy.top/t/topic/jpG1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录