内容简介:111111111111111111111111111111111111111
@Configuration
public class FeichaoMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptor() {
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
System.out.println("公众号:肥朝(id:feichao_java),preHandle");
return true;
}
public void postHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler,
ModelAndView modelAndView) throws Exception {
System.out.println("公众号:肥朝(id:feichao_java),postHandle");
}
public void afterCompletion(HttpServletRequest request,
HttpServletResponse response,
Object handler,
Exception ex) throws Exception {
System.out.println("公众号:肥朝(id:feichao_java),afterCompletion");
}
});
}
}
图解源码
整个过程肥朝小声逼逼几句:
1.根据 spring.factories 上的自动配置,加载 WebMvcAutoConfiguration ,根据序号流程我们知道,最后会把所有的 WebMvcConfigurer ,都加载进名为 delegates 的数组中。我们自定义的 FeichaoMvcConfig 就是 WebMvcConfigurer 的子类。
2. WebMvcConfigurationSupport 是 DelegatingWebMvcConfiguration 的父类。从序号流程我们知道,此时就是把第一步的 delegates 数组,遍历( WebMvcConfigurer )调用 addInterceptor 。addInterceptor这个是SpringMvc的api,从单词名字,我们也很容易知道其意图,这就是所谓的,好的代码会说话。
3.幻想无数,不如动次真格!自己对着上面的图调试一次,箭头和序号都给你标记好了,如果再有人再怎么看源码,请把这个 图解源码系列 甩给他。
写在最后
111111111111111111111111111111111111111 1 1 1111111111111111 1 1 1111111111111111111
以上所述就是小编给大家介绍的《图解源码 | SpringBoot中拓展SpringMVC原理》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 图解源码:MyBatis 的 Mapper 原理
- 图解源码 | MyBatis的Mapper原理
- 图解源码 | 接管SpringMVC的自动配置
- Spark 源码系列(四)图解作业生命周期
- 图解kubernetes服务打散算法的实现源码
- 图解源码:Spring Boot 中自动配置原理
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Head First Design Patterns
Elisabeth Freeman、Eric Freeman、Bert Bates、Kathy Sierra、Elisabeth Robson / O'Reilly Media / 2004-11-1 / USD 49.99
You're not alone. At any given moment, somewhere in the world someone struggles with the same software design problems you have. You know you don't want to reinvent the wheel (or worse, a flat tire),......一起来看看 《Head First Design Patterns》 这本书的介绍吧!