报告处理在创建 ApplicationContext 之前发布的 Spring Boot 应用程序事件的 @EventListener 方法。 此类事件永远无法传递给 Bean 注册的侦听器,因此带注解的方法永远不会静默运行。

受影响的事件有:

示例:


  @Component
  class MyListener {
    @EventListener // 报告:此事件在上下文存在之前发布
    void on(ApplicationStartingEvent event) { ... }
  }

要侦听这些早期事件,请通过 META-INF/spring.factories (org.springframework.context.ApplicationListener) 或 SpringApplication.addListeners(...) 注册侦听器,而不是依赖于 Bean。