Module bus.starter

Class SpringSmartLifecycle

java.lang.Object
org.miaixz.bus.spring.boot.SpringSmartLifecycle
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class SpringSmartLifecycle extends Object implements org.springframework.context.SmartLifecycle, org.springframework.context.ApplicationContextAware
实现SmartLifecycle计算应用程序上下文刷新时间。

该类用于监控和记录Spring应用程序上下文刷新过程中的性能指标。 通过实现SmartLifecycle接口,在应用程序启动过程中自动触发上下文刷新时间的统计, 并将统计信息添加到启动报告器中,为应用程序启动性能分析提供数据支持。

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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    根模块名称常量

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors
    Constructor
    Description
    构造函数,初始化SpringSmartLifecycle
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    获取生命周期组件的执行阶段
    boolean
    检查生命周期组件是否正在运行
    void
    setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
    设置应用程序上下文
    void
    启动生命周期组件
    void
    停止生命周期组件

    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.SmartLifecycle

    isAutoStartup, stop
  • Field Details

  • Constructor Details

    • SpringSmartLifecycle

      public SpringSmartLifecycle(StartupReporter startupReporter)
      构造函数,初始化SpringSmartLifecycle
      Parameters:
      startupReporter - 启动报告器实例
  • Method Details

    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      设置应用程序上下文
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Parameters:
      applicationContext - 应用程序上下文
      Throws:
      org.springframework.beans.BeansException - 如果设置上下文时发生异常
    • start

      public void start()
      启动生命周期组件

      在应用程序启动过程中调用此方法,用于计算应用程序上下文刷新时间。 创建并初始化上下文刷新阶段统计信息和根模块统计信息,并将统计信息添加到启动报告器中。

      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      停止生命周期组件

      此方法为空实现,因为不需要在停止时执行任何操作

      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • isRunning

      public boolean isRunning()
      检查生命周期组件是否正在运行
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
      Returns:
      始终返回false,表示此组件不需要持续运行
    • getPhase

      public int getPhase()
      获取生命周期组件的执行阶段
      Specified by:
      getPhase in interface org.springframework.context.Phased
      Specified by:
      getPhase in interface org.springframework.context.SmartLifecycle
      Returns:
      返回Integer.MIN_VALUE,表示此组件应该在最早阶段执行