关于WebMvcConfigurationSupport的大坑-静态资源访问不了

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);
 
    }

原文地址:https://www.cnblogs.com/hellohero55/p/12072465.html