与其明天开始,不如现在行动!
文章目录
- web开发
- 1 web场景
- 1.1 自动配置
- 1.2 默认效果
- 💎总结
web开发
SpringBoot的web开发能力是由SpringMVC提供的
1 web场景
1.1 自动配置
- 整合web场景
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
-
引入自动配置
autoconfigure
-
EnableAutoConfiguration
注解使用@Import({AutoConfigurationImportSelector.class})
批量导入组件 -
加载
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
文件中配置的所有组件 -
所有web自动配置类如下
org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration =====以下是响应式web场景的自动配置类,和现在的没关系 org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration org.springframework.boot.autoconfigure.web.reactive.ReactiveMultipartAutoConfiguration org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration org.springframework.boot.autoconfigure.web.reactive.WebSessionIdResolverAutoConfiguration org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorAutoConfiguration org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration ======== org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
-
配置类绑定了配置文件的一堆配置项
- SpringMVC所有配置以
spring.mvc
开头 - web场景通用配置
spring.web
- 文件上传配置
spring.server.multipart
- 服务器的配置
server
(如:编码方式)
- SpringMVC所有配置以
1.2 默认效果
- 包含了
ContentNegotiatingViewResolver
和BeeanNameViewResolver
组件,方便视图解析 - 默认的静态资源处理机制:静态资源放在
static
文件夹下即可直接访问 - 自动注册
Converter
、GenericConverter
和Formatter
Bean组件,适配常见数据类型转换和格式化需求 - 支持
HttpMessageConverters
,方便返回JSON等数据类型 - 自动注册
MessageCodesResolver
,方便国际化及错误消息处理 - 支持静态的
index.html
- 自动使用
ConfigurableWebBindingInitializer
bean组件,实现消息处理、数据绑定、类型转化等功能
💎总结
本文中若是有出现的错误请在评论区或者私信指出,我再进行改正优化,如果文章对你有所帮助,请给博主一个宝贵的三连,感谢大家😘!!!