feat: 健康检查

原因
    健康检查

修改
    健康检查
This commit is contained in:
zengxiaobo 2024-07-15 18:49:08 +08:00
parent 44d73ab360
commit 2c2b0dafb0
2 changed files with 25 additions and 6 deletions

View File

@ -4,10 +4,7 @@ import cn.axzo.foundation.util.FastjsonUtils;
import cn.axzo.foundation.web.support.AppRuntime;
import cn.axzo.foundation.web.support.context.AxContextInterceptor;
import cn.axzo.foundation.web.support.exception.AbstractExceptionHandler;
import cn.axzo.foundation.web.support.interceptors.CallerAppInterceptor;
import cn.axzo.foundation.web.support.interceptors.PrettyPrintInterceptor;
import cn.axzo.foundation.web.support.interceptors.PrintVerboseInterceptor;
import cn.axzo.foundation.web.support.interceptors.TraceInterceptor;
import cn.axzo.foundation.web.support.interceptors.*;
import cn.axzo.foundation.web.support.resolvers.AxContextResolver;
import cn.axzo.foundation.web.support.resolvers.CallerAppResolver;
import com.alibaba.fastjson.JSONArray;
@ -189,6 +186,7 @@ public class DefaultWebMvcConfig extends DelegatingWebMvcConfiguration implement
registry.addInterceptor(new PrettyPrintInterceptor());
registry.addInterceptor(new CallerAppInterceptor(appRuntime));
registry.addInterceptor(new TraceInterceptor());
registry.addInterceptor(new CheckDeathInterceptor());
super.addInterceptors(registry);
@ -238,8 +236,6 @@ public class DefaultWebMvcConfig extends DelegatingWebMvcConfiguration implement
//添加一个空的根实现. 避免爬虫访问到根路径后一直打印PageNotFound. 项目中可以覆盖 / 根路径的实现
registry.addStatusController("/", HttpStatus.NO_CONTENT);
registry.addStatusController("/favicon.ico", HttpStatus.NO_CONTENT);
//健康检查
registry.addStatusController("/checkDeath", HttpStatus.OK);
super.addViewControllers(registry);
}

View File

@ -0,0 +1,23 @@
package cn.axzo.foundation.web.support.interceptors;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CheckDeathInterceptor implements HandlerInterceptor {
private static final String CHECK_DEATH_URL = "/checkDeath";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (CHECK_DEATH_URL.equals(request.getRequestURI())) {
response.setStatus(HttpStatus.OK.value());
return false;
}
return true;
}
}