标签:intercept 有关 tps 文档 icc reg automatic work custom
7.1.1. Spring MVC Auto-configuration
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:
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).If you want to keep those Spring Boot MVC customizations and make more MVC customizations (interceptors, formatters, view controllers, and other features), you can add your own
@Configuration
class of typeWebMvcConfigurer
but without@EnableWebMvc
.If you want to provide custom instances of
RequestMappingHandlerMapping
,RequestMappingHandlerAdapter
, orExceptionHandlerExceptionResolver
, and still keep the Spring Boot MVC customizations, you can declare a bean of typeWebMvcRegistrations
and use it to provide custom instances of those components.If you want to take complete control of Spring MVC, you can add your own
@Configuration
annotated with@EnableWebMvc
, or alternatively add your own@Configuration
-annotatedDelegatingWebMvcConfiguration
as described in the Javadoc of@EnableWebMvc
.
SpringBoot官方文档中,SpringBoot已经提供了SpringMVC大部分工作场景所需的自动配置,可以直接使用。
默认配置有:
1、SpringBoot在自动配置很多组件的时候,先看容器中有没有用户自己配置的组件(@Bean、@Component)如果有就用用户配置的,如果没有就自动配置;有些组件可以有多个,例如viewResolver,会将用户配置的和自己默认的组合起来
2、在SpringBoot中会有非常多的xxxConfigurer进行扩展配置。
编写一个配置类(@Configuration),实现WebMvcConfigurer接口进行扩展,不能标注@EnableWebMvc注解,重写接口提供的方法即可。可以既保留所有自动配置,也能用扩展的配置。
例如添加视图映射:
在启动时会将所有WebMvcConfiurer相关配置都调用一遍,最终容器中所有Configurer斗湖一起起作用。
最终SpringMVC的自动配置和扩展配置都会起作用
如果要完全接管SpringMVC,就不需要自动配置了,所有内容都自己配。类似于SSM开发时使用SpringMVC。 只需要在配置类上添加@EnableWebMvc即可
标签:intercept 有关 tps 文档 icc reg automatic work custom
原文地址:https://www.cnblogs.com/ELAIRS/p/12242357.html