在配置拦截器时,可以继承WebMvcConfigurationSupport,也可以实现WebMvcConfigurer,但继承WebMvcConfigurationSupport类是会导致自动配置失效的。

这是因为在 springboot的web自动配置类 WebMvcAutoConfiguration 上有条件注解

@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)

这个注解的意思是在项目类路径中 缺少 WebMvcConfigurationSupport类型的bean时改自动配置类才会生效,所以继承 WebMvcConfigurationSupport 后需要自己再重写相应的方法。

这时候就需要重新指定静态资源

配置拦截器继承WebMvcConfigurationSupport时默认配置失效问题,swagger打不开了

上代码:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**").addResourceLocations(
            "classpath:/static/");
    registry.addResourceHandler("swagger-ui.html").addResourceLocations(
            "classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations(
            "classpath:/META-INF/resources/webjars/");
    super.addResourceHandlers(registry);
}

 

相关文章:

  • 2021-11-20
  • 2022-12-23
  • 2021-08-29
  • 2021-09-14
  • 2021-07-16
  • 2021-11-01
  • 2022-01-10
猜你喜欢
  • 2021-07-02
  • 2021-09-19
  • 2022-12-23
  • 2021-08-28
  • 2021-06-28
  • 2022-12-23
相关资源
相似解决方案