i有一个应用程序,可以花时间从其春季上下文初始化。 我正在寻找一种揭示端点以了解应用程序是否启动的方法。
T08:46:29.372 Starting Application using Java 21.0.3 with PID 33532
T08:46:31.319 RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
T08:46:32.251 RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 911 ms. Found 63 JPA repository interfaces.
T08:46:33.976 TomcatWebServer : Tomcat initialized with port 8080 (http)
T08:46:33.989 StandardService : Starting service [Tomcat]
T08:46:33.989 StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.34]
T08:46:34.073 Initializing Spring embedded WebApplicationContext
T08:46:34.074 ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4628 ms
>>> start to expose here
[...]
T08:46:57.954 TomcatWebServer : Tomcat started on port 8080 (http) with context path '/api'
T08:46:57.991 Application : Started Application in 29.494 seconds (process running for 30.953)
我将Springboot与Tomcat嵌入。
。添加Spring-boot-starter-starter-actuator依赖性并配置应用程序。
management.endpoints.web.exposure.include=health
management.health.livenessState.enabled=true
management.health.readinessState.enabled=true
/actuator/health/liveness
和/actuator/health/readiness
将可用。LIVISESINGINE(
health/liveness
)指示应用程序是否正在运行,而REECHINSES(health/readiness
)将为
OUT_OF_SERVICE
,直到应用程序完全准备好处理请求为止。如果需要,您可以创建一个自定义的健康固定器,只有在所有服务加载后才更改状态。这是一种方便且安全的方法,可以在不编写自定义控制器的情况下监视Spring Boot应用程序的状态。