Module bus.starter

Class SpringApplicationRunListener

java.lang.Object
org.miaixz.bus.spring.boot.SpringApplicationRunListener
All Implemented Interfaces:
EventListener, org.springframework.boot.SpringApplicationRunListener, org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationStartedEvent>, org.springframework.core.Ordered

public class SpringApplicationRunListener extends Object implements org.springframework.boot.SpringApplicationRunListener, org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationStartedEvent>, org.springframework.core.Ordered
实现 SpringApplicationRunListenerApplicationListener,计算启动阶段时间。

该类用于监控和记录Spring应用程序启动过程中的各个阶段耗时,支持动态加载和性能统计。 它记录JVM启动、环境准备、上下文初始化等关键阶段的性能指标,为应用程序启动性能分析提供数据支持。

Since:
Java 17+
Author:
Kimi Liu
  • Field Summary

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpringApplicationRunListener(org.springframework.boot.SpringApplication springApplication)
    构造函数,初始化SpringApplicationRunListener
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    contextLoaded(org.springframework.context.ConfigurableApplicationContext context)
    应用程序上下文加载完成时的回调方法
    void
    contextPrepared(org.springframework.context.ConfigurableApplicationContext context)
    应用程序上下文准备完成时的回调方法
    void
    environmentPrepared(org.springframework.boot.ConfigurableBootstrapContext bootstrapContext, org.springframework.core.env.ConfigurableEnvironment environment)
    环境准备完成时的回调方法
    int
    获取此监听器的顺序
    void
    onApplicationEvent(org.springframework.boot.context.event.ApplicationStartedEvent event)
    处理应用程序启动事件
    void
    started(org.springframework.context.ConfigurableApplicationContext context, Duration timeTaken)
    应用程序启动完成时的回调方法
    void
    starting(org.springframework.boot.ConfigurableBootstrapContext bootstrapContext)
    应用程序启动开始时的回调方法

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.context.ApplicationListener

    supportsAsyncExecution

    Methods inherited from interface org.springframework.boot.SpringApplicationRunListener

    failed, ready
  • Constructor Details

    • SpringApplicationRunListener

      public SpringApplicationRunListener(org.springframework.boot.SpringApplication springApplication)
      构造函数,初始化SpringApplicationRunListener
      Parameters:
      springApplication - Spring应用程序实例
  • Method Details

    • starting

      public void starting(org.springframework.boot.ConfigurableBootstrapContext bootstrapContext)
      应用程序启动开始时的回调方法

      记录JVM启动阶段的开始和结束时间,计算JVM启动耗时

      Specified by:
      starting in interface org.springframework.boot.SpringApplicationRunListener
      Parameters:
      bootstrapContext - 可配置的引导上下文
    • environmentPrepared

      public void environmentPrepared(org.springframework.boot.ConfigurableBootstrapContext bootstrapContext, org.springframework.core.env.ConfigurableEnvironment environment)
      环境准备完成时的回调方法

      记录环境准备阶段的开始和结束时间,计算环境准备耗时,并设置应用程序名称

      Specified by:
      environmentPrepared in interface org.springframework.boot.SpringApplicationRunListener
      Parameters:
      bootstrapContext - 可配置的引导上下文
      environment - 可配置的环境
    • contextPrepared

      public void contextPrepared(org.springframework.context.ConfigurableApplicationContext context)
      应用程序上下文准备完成时的回调方法

      记录应用程序上下文准备阶段的开始和结束时间,计算上下文准备耗时, 并添加SpringApplication中收集的初始化器统计信息

      Specified by:
      contextPrepared in interface org.springframework.boot.SpringApplicationRunListener
      Parameters:
      context - 可配置的应用程序上下文
    • contextLoaded

      public void contextLoaded(org.springframework.context.ConfigurableApplicationContext context)
      应用程序上下文加载完成时的回调方法

      记录应用程序上下文加载阶段的开始和结束时间,计算上下文加载耗时, 并注册启动报告器和生命周期处理器

      Specified by:
      contextLoaded in interface org.springframework.boot.SpringApplicationRunListener
      Parameters:
      context - 可配置的应用程序上下文
    • started

      public void started(org.springframework.context.ConfigurableApplicationContext context, Duration timeTaken)
      应用程序启动完成时的回调方法

      记录应用程序刷新阶段的开始和结束时间,计算刷新耗时, 添加所有阶段的统计信息到启动报告器,并标记应用程序启动完成

      Specified by:
      started in interface org.springframework.boot.SpringApplicationRunListener
      Parameters:
      context - 可配置的应用程序上下文
      timeTaken - 启动所花费的时间
    • onApplicationEvent

      public void onApplicationEvent(org.springframework.boot.context.event.ApplicationStartedEvent event)
      处理应用程序启动事件

      当接收到ApplicationStartedEvent事件时调用此方法

      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.boot.context.event.ApplicationStartedEvent>
      Parameters:
      event - 应用程序启动事件
    • getOrder

      public int getOrder()
      获取此监听器的顺序
      Specified by:
      getOrder in interface org.springframework.core.Ordered
      Returns:
      顺序值,值越小优先级越高