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