From 95f340d6093f0966dbaca010afdba9cbf848fa99 Mon Sep 17 00:00:00 2001 From: chentianming Date: Fri, 1 Apr 2022 17:39:17 +0800 Subject: [PATCH] =?UTF-8?q?GlobalInterceptor=E6=96=87=E6=A1=A3=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a626620..d6c1b2c 100644 --- a/README.md +++ b/README.md @@ -562,19 +562,26 @@ public interface ErrorDecoder { ### 全局应用拦截器 -如果我们需要对整个系统的的http请求执行统一的拦截处理,可以自定义实现全局拦截器`BaseGlobalInterceptor`, 并配置成`spring`容器中的`bean`!例如我们需要在整个系统发起的http请求,都带上来源信息。 +如果我们需要对整个系统的的http请求执行统一的拦截处理,可以自定义实现全局拦截器`GlobalInterceptor`, 并配置成`spring`容器中的`bean`!例如我们需要在整个系统发起的http请求,都带上来源信息。 ```java @Component -public class SourceInterceptor extends BaseGlobalInterceptor { - @Override - public Response doIntercept(Chain chain) throws IOException { - Request request = chain.request(); - Request newReq = request.newBuilder() - .addHeader("source", "test") - .build(); - return chain.proceed(newReq); - } +@Order(2) +public class SourceGlobalInterceptor implements GlobalInterceptor { + + @Autowired + private TestService testService; + + @Override + public Response intercept(Chain chain) throws IOException { + Request request = chain.request(); + Request newReq = request.newBuilder() + .addHeader("source", "test") + .build(); + System.out.println("===========执行全局重试==========="); + testService.test(); + return chain.proceed(newReq); + } } ```