这可能不是解决您的问题的最优雅的解决方案,但可以解决问题。
只需拦截执行器调用并在发送响应后执行您需要执行的操作。
@Component
public class ActuatorHandlerInterceptorAdapter extends HandlerInterceptorAdapter {
private static final Logger logger = LoggerFactory
.getLogger(ActuatorHandlerInterceptorAdapter.class);
@Override
public void afterCompletion(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex)
throws Exception {
if (request.getRequestURL().toString().contains("actuator/health/liveness")){
System.out.println("Let's do something based on liveness response");
}
if (request.getRequestURL().toString().contains("actuator/health/readiness")){
System.out.println("Let's do something based on readiness response");
}
}
}