SpringBoot的web开发

与其明天开始,不如现在行动!


web开发

SpringBoot的web开发能力是由SpringMVC提供的

1 web场景

1.1 自动配置

  1. 整合web场景
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
  1. 引入自动配置autoconfigure

  2. EnableAutoConfiguration注解使用@Import({AutoConfigurationImportSelector.class})批量导入组件

  3. 加载META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports文件中配置的所有组件

  4. 所有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
    
  5. 配置类绑定了配置文件的一堆配置项

    1. SpringMVC所有配置以spring.mvc开头
    2. web场景通用配置spring.web
    3. 文件上传配置spring.server.multipart
    4. 服务器的配置server(如:编码方式)

1.2 默认效果

  1. 包含了ContentNegotiatingViewResolverBeeanNameViewResolver组件,方便视图解析
  2. 默认的静态资源处理机制:静态资源放在static文件夹下即可直接访问
  3. 自动注册 ConverterGenericConverterFormatter Bean组件,适配常见数据类型转换格式化需求
  4. 支持 HttpMessageConverters,方便返回JSON等数据类型
  5. 自动注册 MessageCodesResolver,方便国际化及错误消息处理
  6. 支持静态的 index.html
  7. 自动使用 ConfigurableWebBindingInitializer bean组件,实现消息处理、数据绑定、类型转化等功能

💎总结

本文中若是有出现的错误请在评论区或者私信指出,我再进行改正优化,如果文章对你有所帮助,请给博主一个宝贵的三连,感谢大家😘!!!


本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码

)">
< <上一篇
下一篇>>