SpringBoot加载静态资源内部流程

1、问题描述

利用springboot构建分布式项目时,webapp模块中需要定义配置文件application.yml来指定服务端口号。

在springboot的内部是如何去starter的呢?如何去加载静态资源的呢?

2、springboot内部

从org.springframework.boot.autoconfigure.web.ServerProperties类开始看起。

springboot内置web容器中使用了ServerProperties,通过@ConfigurationProperties注解将配置信息映射到ServerProperties。

3、加载静态资源流程

从org.springframework.boot.autoconfigure.web.ResourceProperties类看起。

@ConfigurationProperties(
    prefix = "spring.resources",
    ignoreUnknownFields = false
)
public class ResourceProperties {
    private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]
{"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"};
    private String[] staticLocations;
    private boolean addMappings;
    private final ResourceProperties.Chain chain;
    private final ResourceProperties.Cache cache;

.........

}
发布了737 篇原创文章 · 获赞 65 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qq_41723615/article/details/104209235