Spring boot的Spring MVC自动配置

自动配置

参考官网
https://docs.spring.io/spring-boot/docs/1.5.10.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications
Spring boot的Spring MVC自动配置
Spring MVC auto-configuration
Spring Boot自动配置好了SpringMVC

Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
自动配置了ViewResolver视图解析器
根据方法的返回值得到视图对象View,视图对象决定如何渲染转发,重定向

ContentNegotiatingViewResolver
组合所有的视图解析器

可以自定义给容器中,添加一个视图解析器
自动的将其组合进来

Support for serving static resources, including support for WebJars (see below)
静态资源文件夹路径,webjars

Automatic registration of Converter, GenericConverter, Formatter beans.
自动注册了of Converter , GenericConverter , Formatter beans.

Converter
转换器
public String hello(User user):类型转换使用Converter

Formatter
格式化器,2017.12.17===Date
自定义格式化器转换器,只需要放在容器中即可

Support for HttpMessageConverters (see below).
HttpMessageConverter
SpringMVC用来转换Http请求和响应的,User—Json

HttpMessageConverters
是从容器中确定,获取所有的HttpMessageConverter

自定义给容器中添加HttpMessageConverter
只需要将自己的组件注册容器中@Bean,@Component

Automatic registration of MessageCodesResolver (see below).
定义错误代码生成规则

Static index.html support.
静态首页访问

Custom Favicon support (see below). favicon.ico
定义网页的图标

Automatic use of a ConfigurableWebBindingInitializer bean (see below).
初始化WebDataBinder,请求数据JavaBean

可以自定义配置一个ConfigurableWebBindingInitializer
添加到容器中,替换默认配置