WebMvcConfigurationSupport是spring boot2.0以后用来替代WebMvcConfigurerAdapter,但是如果你直接用WebMvcConfigurationSupport替换掉WebMvcConfigurerAdap就会发现各种各样的错误。

原因其实就是当我们使用WebMvcConfigurationSupport时WebMvc自动化配置就会失效,刚入门的小白,真的是花了我大量的时间,所以写个帖子绕过在这个坑,最简单的解决办法就是将:

extends WebMvcConfigurationSupport 替换为 implements WebMvcConfigure。
 

或者:

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
         //registry.addResourceHandler("/static/*/**").addResourceLocations("classpath:/static/");
        //重写这个方法,映射静态资源文件
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/resources/")
                .addResourceLocations("classpath:/static/")
                .addResourceLocations("classpath:/public/")
                ;
        super.addResourceHandlers(registry);
 
    }

相关文章:

  • 2022-02-06
  • 2022-12-23
  • 2021-08-31
  • 2021-10-04
  • 2021-06-13
  • 2021-10-19
  • 2021-11-20
猜你喜欢
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2022-12-23
  • 2021-11-20
  • 2021-09-22
相关资源
相似解决方案