docs/Spring全家桶/SpringMVC源码分析/SpringMVC整体源码结构总结.md
ϵһʼȽ servlet3.0 淶ͨù淶ʵ web Ŀ 0xml .
servlet3.0 淶Уservlet ͨ SPI ṩһӿڣServletContainerInitializerSpringServletContainerInitializer onStartup(...) Уִʵ WebApplicationInitializer ӿڵ onStartup(...) ֻҪʵ WebApplicationInitializer ӿڼɣWebApplicationInitializer ӿڵУ onStartup(...) servlet ֶעһ servletDispatcherServlet servlet л spring̾
Ƿ webMvc ַʽ
@EnableWebMvcַʽֻܼҪ
// ʹ@EnableWebMvcעmvc
@Component
@EnableWebMvc
public class MvcConfig {
...
}
Ҫ webMvc һЩʱҪʵ WebMvcConfigurer:
// ʵ WebMvcConfigurerԶ
@Component
public class MyWebMvcConfigurer implements WebMvcConfigurer {
// дWebMvcConfigurerԶ
}
WebMvcConfigurationSupportһַʽ webMvc ʽʵ WebMvcConfigurationSupport
@Component
public class MyWebMvcConfigurationSupport extends WebMvcConfigurationSupport {
// д÷Զ
...
/**
* 磬ӿãֱд addCorsMappings
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
// Լ
...
}
}
ҪעǣʹַʽҪԶʱͲȥʵ WebMvcConfigurer ӿˣӦֱд WebMvcConfigurationSupport еӦд addCorsMappings().
һͼ̣ܽ
Ҳһͼ̣ܽ
ԭӣhttps://my.oschina.net/funcy/blog/4773418 ߸ˮƽд֮ӭָԭףҵתϵȨҵתע