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

Spring boot 静态资源访问

时间:2019-11-23 16:06:30      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:iis   efault   smi   stat   soa   d3d   source   uft   cm5   

Spring Boot 默认静态资源访问

spring-configuration-metadata.json
{
      "name": "spring.resources.static-locations",
      "type": "java.lang.String[]",
      "description": "Locations of static resources. Defaults to classpath:[\/META-INF\/resources\/, \/resources\/, \/static\/, \/public\/].",
      "sourceType": "org.springframework.boot.autoconfigure.web.ResourceProperties",
      "defaultValue": [
        "classpath:\/META-INF\/resources\/",
        "classpath:\/resources\/",
        "classpath:\/static\/",
        "classpath:\/public\/"
      ]
    }

技术图片

自定义静态资源地址

例子1

请求路径:/image/**
请求文件:classpath:/images/

@Configurationpublic class ImageMvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/image/**")
                .addResourceLocations("classpath:/images/");
    }
}
例子2

请求路径:/resources/**
请求文件:/public, classpath:/static/

@Configuration@EnableWebMvcpublic class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**")
            .addResourceLocations("/public", "classpath:/static/")
            .setCachePeriod(31556926);
    }
}
例子3
spring:
  mvc:
    static-path-pattern: /image/**
  resources:
    static-locations: classpath:/images/

Spring boot 静态资源访问

标签:iis   efault   smi   stat   soa   d3d   source   uft   cm5   

原文地址:https://www.cnblogs.com/yang21/p/11918097.html

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