美文网首页
springboot 配置过滤器和拦截器

springboot 配置过滤器和拦截器

作者: 我叫myq | 来源:发表于2019-05-29 16:53 被阅读0次

1.配置拦截器

创建拦截器类 实现HandlerInterceptor接口

创建springmvc配置类 实现WebMvcConfigurer 中的addInterceptors方法(注意:WebMvcConfigurer和@EnableWebMvc注解混合使用时须知:@EnableWebMvc开启后,意味着springmvc环境被你完全接管了(若不定义需要那些bean,确实啥都没有了),也就是说混合使用会覆盖@EnableAutoConfiguration关于WebMvcAutoConfiguration的配置) 

1.配置过滤器

创建过滤器类

配置FilterRegistrationBean bean

小结:

在本例子中我使用的mvc配置类是实现WebMvcConfigurer ,这种方式不会覆盖@EnableAutoConfiguration关于WebMvcAutoConfiguration的配置

当然除了这种方式我们还可以选择:

@EnableWebMvc + implements WebMvcConfigurer : 会覆盖@EnableAutoConfiguration关于WebMvcAutoConfiguration的配置

继承 WebMvcConfigurationSupport :会覆盖@EnableAutoConfiguration关于WebMvcAutoConfiguration的配置

继承DelegatingWebMvcConfiguration :会覆盖@EnableAutoConfiguration关于WebMvcAutoConfiguration的配置

相关文章

网友评论

      本文标题:springboot 配置过滤器和拦截器

      本文链接:https://www.haomeiwen.com/subject/dxmytctx.html