27.1.1 Spring MVC auto-configuration

Spring Boot为Spring MVC提供的auto-configuration适用于大多数应用,并在Spring默认功能上添加了以下特性:

  • 引入ContentNegotiatingViewResolverBeanNameViewResolverbeans。
  • 对静态资源的支持,包括对WebJars的支持。
  • 自动注册Converter,GenericConverter,Formatter beans
  • HttpMessageConverters的支持。
  • 自动注册MessageCodeResolver
  • 对静态index.html的支持。
  • 对自定义Favicon的支持。
  • 自动使用ConfigurableWebBindingInitializerbean。

如果保留Spring Boot MVC特性,你只需添加其他的MVC配置(拦截器,格式化处理器,视图控制器等)。

你可以添加自己的WebMvcConfigurerAdapter类型的@Configuration类,而不需要注解@EnableWebMvc。如果希望使用自定义的RequestMappingHandlerMappingRequestMappingHandlerAdapter,或ExceptionHandlerExceptionResolver,你可以声明一个WebMvcRegistrationsAdapter实例提供这些组件。

如果想全面控制Spring MVC,你可以添加自己的@Configuration,并使用@EnableWebMvc注解。

results matching ""

    No results matching ""