zoukankan      html  css  js  c++  java
  • springboot无法访问静态资源

    无法访问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,可以访问静态资源了
  • 相关阅读:
    2019-2020-1 20199302《Linux内核原理与分析》第九周作业
    MySQL 优化
    ElasticSearch实战
    redis实战
    ElasticSearch
    Zookeeper
    redis
    Jenkins 持续交付
    JDK 1.8 新特性之Stream
    cat-监控系统
  • 原文地址:https://www.cnblogs.com/lljh/p/11904269.html
Copyright © 2011-2022 走看看