Spring static resource 自动配置和手动配置
自动配置
按照Spring boot官网的说法,如果我们使用了spring-boot-starter-web
这个模块,那么就会使用Spring mvc auto-configuration.主要包括以下内容:
- Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
- Support for serving static resources, including support for WebJars.
- Automatic registration of Converter, GenericConverter, Formatter beans.
- Support for HttpMessageConverters .
- Automatic registration of MessageCodesResolver .
- Static index.html support.
- Custom Favicon support .
- Automatic use of a ConfigurableWebBindingInitializer bean.
在自动配置基础上增加web mvc的配置
新建配置类,并且加上@Configuration
注解并继承WebMvcConfigurerAdapter
,并且不能使用@EnableWebMvc
注解
完全独立的配置web mvc
直接在配置类上加上@Configuration
和@EnableWebMvc
注解