我想获取请求正文,因此我决定实现HttpResponseInterceptor接口。如何正确做?
public class CustomHttpInterceptor implements org.apache.http.HttpRequestInterceptorHttpRequestInterceptor {
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
}
}
我应该将CustomHttpInterceptor创建为bean吗?如何添加它对于Spring也可见?
最佳答案
您还可以使用spring提供的HandlerInterceptorAdapter
实现接口,并添加一个实现WebMvcConfigurer
的Config类,该类具有一个方法
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoggerInterceptor());
}
您可以在https://www.baeldung.com/spring-mvc-handlerinterceptor上找到更多详细信息