Spring Boot为Spring MVC 提供了 auto-configuration.

The auto-configuration adds the following features on top of Spring’s defaults:

  • Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
  • Support for serving static resources, including support for WebJars 。
  • Automatic registration of Converter, GenericConverter, and Formatter beans。
  • Support for HttpMessageConverters.
  • Automatic registration of MessageCodesResolver.
  • Static index.html support.
  • Custom Favicon support.
  • Automatic use of a ConfigurableWebBindingInitializer bean.

如果要保留 Spring Boot MVC 功能,并且想要添加其他 MVC 配置(拦截器、操作器、视图控制器和其他功能),则可以添加您自己的@Configuration类类型 WebMvcConfigurer,但不要使用@EnableWebMvc。如果要提供请求映射处理程序映射、请求映射处理程序适配器或异常处理程序的自定义实例,可以声明 WebMvc 注册适配器实例以提供此类组件。

如果要完全控制 Spring MVC,可以添加您自己的@Configuration,并@EnableWebMvc。不过使用了@EnableWebMvc就没有原来了Spring Boot 自动配置的MVC的那些默认配置了。

 

发表评论