web开发
1)、创建SpringBoot应用,选中我们需要的模块;
2)、SpringBoot已经默认将这些场景已经配置好了,只需要在配置文件中指定少量配置就可以运行起来
3)、自己编写业务代码;
自动配置原理?
这个场景SpringBoot帮我们配置了扫码?能不能修改?能不能改哪些配置?能不能扩展?xxx
xxxAutoConfiguration:帮我们给容器中自动配置组件;
xxxProperties:配置类来 封装配置文件的内容;
2、SpringBoot对静态资源的 映射规则
@ConfigurationProperties(prefix="spring.resources",ignoreUnknownFields=false)
public class ResourceProperties implements ResourceLoaderAware{
//可以设置和静态资源又关的的 参数,缓存时间
1 public void addResourceHandlers(ResourceHandlerRegistry registry) { 2 if (!this.resourceProperties.isAddMappings()) { 3 logger.debug("Default resource handling disabled"); 4 } else { 5 Duration cachePeriod = this.resourceProperties.getCache().getPeriod(); 6 CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl(); 7 if (!registry.hasMappingForPattern("/webjars/**")) { 8 this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{"/webjars/**"}).addResourceLocations(new String[]{"classpath:/META-INF/resources/webjars/"}).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl)); 9 } 10 11 String staticPathPattern = this.mvcProperties.getStaticPathPattern(); 12 if (!registry.hasMappingForPattern(staticPathPattern)) { 13 this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{staticPathPattern}).addResourceLocations(getResourceLocations(this.resourceProperties.getStaticLocations())).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl)); 14 } 15 16 } 17 }