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;
.........
}