通过之前的学习,我们可以将web开发分为以下几步
-
场景strater(通过maven导入需要的场景,如:web场景)
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
-
xxxxAutoConfiguration(SpringBoot提供某个组建的自动配置)
-
导入xxxx组件(SpringBoot底层提供)
-
绑定xxxxProperties(SpringBoot定义规则)
-
绑定配置文件项(可以通过yaml文件改变默认配置文件项)
定制化的常见方式
-
修改配置文件
-
编写一个自定义配置类 xxxxconfiguration + @Bean替换、增加容器中默认组件
-
Web应用 编写一个配置类实现WebMvcConfiguration即可定制化web功能(常用),如下
@Configuration public class AdminWebConfig implements WebMvcConfigurer { }
-
@EnableWebMvc + WebMvcConfiguration = 全面接管SpringMVC,所有规则全部自己重新配置,实现定制和扩展功能
-
WebMvcAutoConfiguration是默认的SpringBoot配置类,前提是没有配置WebMvcConfigurationSupport
@ConditionalOnMissingBean({WebMvcConfigurationSupport.class})
-
@EnableWebMvc 配置了WebMvcConfigurationSupport,所以SpringMVC的所有规则都会失效
@Import({DelegatingWebMvcConfiguration.class}) public @interface EnableWebMvc {
-