Spring Boot添加Http请求拦截器

Spring Boot添加Http请求拦截器,第1张

Spring Boot添加Http请求拦截器

由于你使用的是Spring Boot,因此我假设你希望在可能的情况下依靠Spring的自动配置。要添加其他自定义配置(例如你的拦截器),只需提供一个配置或

WebMvcConfigurerAdapter

这是一个配置类的例子:

@Configurationpublic class WebMvcConfig extends WebMvcConfigurerAdapter {  @Autowired   HandlerInterceptor yourInjectedInterceptor;  @Override  public void addInterceptors(InterceptorRegistry registry) {    registry.addInterceptor(...)    ...    registry.addInterceptor(getYourInterceptor());     registry.addInterceptor(yourInjectedInterceptor);    // next two should be avoid -- tightly coupled and not very testable    registry.addInterceptor(new YourInterceptor());    registry.addInterceptor(new HandlerInterceptor() {        ...    });  }}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4908323.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存