前言:通过springboot中的mvc自动配置类源码来发现和理解springmvc在springboot中是如何实现的
作为一个web工程,肯定有一块地方是用于存放静态文件的,比如html,css,js等。
不同于普通的web工程,springboot项目是没有webapp目录的,那么这些静态文件应该从哪里获取呢?
1.从mvc自动配置类查找静态文件的路径配置
其中可以发现一个方法:addResourceHandler
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!this.resourceProperties.isAddMappings()) {
logger.debug("Default resource handling disabled");
return;
}
Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheCon