jar:webapp
自动装配
springboot:配置、能不能修改、哪些可以修改、能否扩展
xxxAutoConfiguration向容器中自动配置组件
XXXProperties:自动装配类,装配配置文件中的自定义的一些内容
web开发需求:
1.导入静态资源
2.首页
3.jsp,模板引擎Thymeleaf
4.装配扩展SpringMVC
5.增删改查
6.拦截器
7.国际化
静态资源导入
双击shift搜索WebMvcAutoConfiguration,在ctrl+f找到addResourceHandlers,分析WebMvcAutoConfiguration下的addResourceHandlers 关于静态资源导入解决方法
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//如果自定义资源已经被导入
if (!this.resourceProperties.isAddMappings()) {
logger.debug("Default resource handling disabled");
} else {
Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl();
if (!registry.hasMappingForPattern("/webjars/**")) {
this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{"/webjars/**"}).addResourceLocations(new String[]{"classpath:/META-INF/resources/webjars/"}).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl));
}
String staticPathPattern = this.mvcProperties.getStaticPathPattern();
if (!registry.hasMappingForPattern(staticPathPattern)) {
this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{staticPathPattern}).addResourceLocations(WebMvcAutoConfiguration.getResourceLocations(this.resourceProperties.getStaticLocations())).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl));
}
}
}
第一种导入方式:去wenjars上找
if (!registry.hasMappingForPattern("/webjars/")) {
this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{"/webjars/"}).addResourceLocations(new