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
FieldsFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionSpringSmartLifecycle(StartupReporter startupReporter) 构造函数,初始化SpringSmartLifecycle -
Method Summary
Modifier and TypeMethodDescriptionintgetPhase()获取生命周期组件的执行阶段boolean检查生命周期组件是否正在运行voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) 设置应用程序上下文voidstart()启动生命周期组件voidstop()停止生命周期组件Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
isAutoStartup, stop
-
Field Details
-
ROOT_MODULE_NAME
根模块名称常量- See Also:
-
-
Constructor Details
-
SpringSmartLifecycle
构造函数,初始化SpringSmartLifecycle- Parameters:
startupReporter- 启动报告器实例
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException 设置应用程序上下文- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Parameters:
applicationContext- 应用程序上下文- Throws:
org.springframework.beans.BeansException- 如果设置上下文时发生异常
-
start
public void start()启动生命周期组件在应用程序启动过程中调用此方法,用于计算应用程序上下文刷新时间。 创建并初始化上下文刷新阶段统计信息和根模块统计信息,并将统计信息添加到启动报告器中。
- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()停止生命周期组件此方法为空实现,因为不需要在停止时执行任何操作
- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()检查生命周期组件是否正在运行- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle- Returns:
- 始终返回false,表示此组件不需要持续运行
-
getPhase
public int getPhase()获取生命周期组件的执行阶段- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle- Returns:
- 返回Integer.MIN_VALUE,表示此组件应该在最早阶段执行
-