zoukankan      html  css  js  c++  java
  • 关于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);
     
        }

  • 相关阅读:
    操作系统-微内核操作系统
    设备管理-虚设备与SPOOLING技术
    设备管理-数据传输控制方式
    文件管理-空闲存储空间的管理
    文件管理-索引文件结构
    Alpha冲刺8
    Alpha冲刺7
    Alpha冲刺6
    Alpha冲刺5
    Alpha冲刺4
  • 原文地址:https://www.cnblogs.com/hellohero55/p/12072465.html
Copyright © 2011-2022 走看看