SpringBoot----SpringMVC的自动配置原理之容器模式23

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 and BeanNameViewResolver beans.
  • Support for serving static resources, including support for WebJars (covered later in this document)).
  • Automatic registration of Converter, GenericConverter, and Formatter 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)将用户配置的和自己默

认的组合起来;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值