码迷,mamicode.com
首页 > 编程语言 > 详细

springboot无法访问静态资源

时间:2019-11-21 11:46:20      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:路径   img   att   private   code   bsp   本地   静态   ica   

无法访问static下的静态资源

技术图片

 

 

 1.在application.yml中添加

  resources:
    static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:./../images

 2、配置webconfig

  

@EnableWebMvc
@Configuration
public class WebAppConfig implements WebMvcConfigurer {

    private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
            "classpath:/META-INF/resources/", "classpath:/resources/",
            "classpath:/static/", "classpath:/public/" };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AppInterceptor()).addPathPatterns("/**").excludePathPatterns("");
    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置server虚拟路径,handler为页面中访问的目录,locations为files相对应的本地路径
        registry.addResourceHandler("/static/**")
                .addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
    }

}

 

ok,可以访问静态资源了

springboot无法访问静态资源

标签:路径   img   att   private   code   bsp   本地   静态   ica   

原文地址:https://www.cnblogs.com/lljh/p/11904269.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!