18. The principle of customization


[Shang Silicon Valley] SpringBoot2 Zero-Basic Introductory Tutorial - Lecturer: Lei Fengyang
Notes

The road is still going on, the dream is still waiting

1. Common ways of customization

● Modify the configuration file;
● xxxxxCustomizer;
● Write a custom configuration class xxxConfiguration; + @Bean replaces and adds default components in the container; view parser
● Web application writes a configuration class to implement WebMvcConfigurer to customize web functions; + @Bean Extend some components to the container

@Configuration
public class AdminWebConfig implements WebMvcConfigurer

● @EnableWebMvc + WebMvcConfigurer —— @Bean can fully take over SpringMVC, and all rules can be reconfigured by itself; realize customization and extension functions
○ Principle
○ 1. WebMvcAutoConfiguration The default automatic configuration function class of SpringMVC. Static resources, welcome page...
○ 2. Once @EnableWebMvc is used,. Can @Import(DelegatingWebMvcConfiguration.class)
○ 3. The role of DelegatingWebMvcConfiguration only guarantees the most basic use of SpringMVC
■ Take the WebMvcConfigurer from all systems. The customization of all functions is the combination of these WebMvcConfigurers to take effect
■ Automatic configuration of some very low-level components. RequestMappingHandlerMapping, the components that these components depend on are obtained from the container
public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport
○ 4. The configuration in WebMvcAutoConfiguration must be @ConditionalOnMissingBean(WebMvcConfigurationSupport.class)
○ 5. @EnableWebMvc leads to WebMvcAuto Configuration does not take effect.
●……

2. Principle analysis routine

Scenario starter - xxxxAutoConfiguration - import xxx components - bind xxxProperties - bind configuration file items

Guess you like

Origin blog.csdn.net/zhao854116434/article/details/130251342