jar :webapp!
自动装配
springboot到底帮我们配置了什么?我们能不能进行修改?能修改那些东西?能不能扩展?
- xxxxAutoConfiguration…向容器中自动配置组件
- xxxxProperties:自动配置类,装配配置文件中自定义的一些内容!
要解决的问题:
-
导入静态资源
-
首页
-
jsp,模板引擎Thymeleaf
-
装配扩展SpringMVC
-
增删改查
-
拦截器
-
国际化!
静态资源
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//如果resourceProperties已经被自定义了,
if (!this.resourceProperties.isAddMappings()) {
logger.debug(“Default resource handling disabled”);
} else {
//从"classpath:/META-INF/resources/webjars/“获取”/webjars/"下的所有资源
this.addResourceHandler(registry, "/webjars/", “classpath:/META-INF/resources/webjars/”);
this.addResourceHandler(registry, this.mvcProperties.getStaticPathPattern(), (registration) -> {
registration.addResourceLocations(this.resourceProperties.getStaticLocations());
if (this.servletContext != null) {
//获得静态资源的路径
ServletContextResource resource = new ServletContextResource(this.servletContext, “/”);
registration.addResourceLocations(new Resource[]{resource});
}}); } }
总结:
1、在springboot,我们可以使用一下方式处理静态资源:
- webjars 访问方式:localhost:8080/webjars/
- public、static、/**、resources 访问方式:localhost:8080/
2.优先级:resources>static(默认的)>public
扩展springMVC
如果我们要扩展springmvc,官方建议我们这样去做!

SpringBoot2使用的Spring5,因此将WebMvcConfigurerAdapter改为WebMvcConfigurer










