Spring Boot provides auto-configuration for Spring MVC that works well with most applications.
The auto-configuration adds the following features on top of Spring’s defaults:(springboot默认配置好的SpringMVC配置)
- Inclusion of
ContentNegotiatingViewResolver
andBeanNameViewResolver
beans. - Support for serving static resources, including support for WebJars (covered later in this document)).
- Automatic registration of
Converter
,GenericConverter
, andFormatter
beans. - Support for
HttpMessageConverters
(covered later in this document). - Automatic registration of
MessageCodesResolver
(covered later in this document). - Static
index.html
support. - Custom
Favicon
support (covered later in this document). - Automatic use of a
ConfigurableWebBindingInitializer
bean (covered later in this document).
1.Support for serving static resources, including support for WebJars (covered later in this document)).
这句话的意思是支持静态资源和WebJars静态资源,这里可以看SpringBoot博客第19篇
2.Static index.html
support.
这句话的意思是支持默认自动配置响应首页
,这里可以看SpringBoot博客第19篇
3.Custom Favicon
support (covered later in this document).
这句话意思是支持自动默认响应ico图片获取,这里可以看SpringBoot博客第19篇
4.Automatic registration of Converter
, GenericConverter
, and Formatter
beans.
自动注册Converter、GenericConverter、Formatter。
4.1.Formatter,这里涉及到两个点,第一个是把字符串转成Date类型,第二个是把指定格式的字符串识别然后转成Date类型。
4.2.过程是利用mvcProperties从配置中获取配置,配置作为参数生成转换器放入到容器里面。然后webmvc这个配置类有方法addFormatters从容器中获取转换器。
5.Support for HttpMessageConverters
(covered later in this document).
在配置类中可以看到HttpMessageConverters
这个类在在一个类中作为构造参数,二这个构造器是唯一的,就是说它会从容器中获取。
6.Automatic registration of MessageCodesResolver
(covered later in this document).
这句话的意思是自动注册代码消息处理器
这个是用来定义错误代码生成规则的基本上就不怎么修改配置了,都是用默认的
7.Automatic use of a ConfigurableWebBindingInitializer
bean (covered later in this document).
这个绑定器是用来从接收到的数据绑定到JavaBean的,基本上也不怎么会改了
SpringBoot在自动配置很多组件的时候,先看容器中有没有用户自己配置的(@Bean、@Component)如
果有就用用户配置的,如果没有,才自动配置;如果有些组件可以有多个(ViewResolver)将用户配置的和自己默
认的组合起来;