package cn.edu.tju.component;
import org.springframework.boot.availability.AvailabilityChangeEvent;
import org.springframework.boot.availability.ReadinessState;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Component
public class MyReadinessStateExporter {
@EventListener
public void onStateChange(AvailabilityChangeEvent<ReadinessState> event) {
switch (event.getState()) {
case ACCEPTING_TRAFFIC:
System.out.println("accepting......");
break;
case REFUSING_TRAFFIC:
System.out.println("refusing......");
break;
}
}
}
SpringBoot 官方文档示例:(4)通过Listener获取应用的Readiness状态
最新推荐文章于 2023-10-24 09:28:29 发布
该博客展示了如何使用Spring Boot的`@EventListener`注解监听应用程序的可用性和就绪状态变化。当应用从拒绝流量状态变为接受流量状态时,系统会输出相应的提示信息,表明服务已准备就绪,可以接收外部请求。
摘要由CSDN通过智能技术生成