0
点赞
收藏
分享

微信扫一扫

SpringBoot静态资源的配置


在SpringBoot项目中,默认有5个位置可以用来存放静态资源,分别为:

1、classpath:/META-INF/resources/

2、classpath:/resources/

3、classpath:/static/

4、classpath:/public/

5、/

源码解析   


WebMvcAutoConfiguration


protected void addResourceHandlers(ResourceHandlerRegistry registry) {
super.addResourceHandlers(registry);
if (!this.resourceProperties.isAddMappings()) {
logger.debug("Default resource handling disabled");
} else {
this.addResourceHandler(registry, "/webjars/**", "classpath:/META-INF/resources/webjars/");
this.addResourceHandler(registry, this.mvcProperties.getStaticPathPattern(), this.resourceProperties.getStaticLocations());
}
}

this.mvcProperties.getStaticPathPattern()对应  /

SpringBoot静态资源的配置_java代码

 

this.resourceProperties.getStaticLocations()对应下面

SpringBoot静态资源的配置_spring boot_02

自定义配置,可以通过application.properties定义,也可以通过java代码定义

1.application.properties定义

SpringBoot静态资源的配置_java代码_03

 

2.java代码

SpringBoot静态资源的配置_spring boot_04

 

 

举报

相关推荐

0 条评论