if (!mappedHandler.applyPreHandle(processedRequest, response)) {
return;
-
boolean applyPreHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {
for (int i = 0; i < this.interceptorList.size(); i++) {
HandlerInterceptor interceptor = this.interceptorList.get(i);
if (!interceptor.preHandle(request, response, this.handler)) {
triggerAfterCompletion(request, response, null);
return false;
this.interceptorIndex = i;
return true;
-
void triggerAfterCompletion(HttpServletRequest request, HttpServletResponse response, @Nullable Exception ex) {
for (int i = this.interceptorIndex; i >= 0; i--) {
HandlerInterceptor interceptor = this.interceptorList.get(i);
try {
interceptor.afterCompletion(request, response, this.handler, ex);
catch (Throwable ex2) {
logger.error("HandlerInterceptor.afterCompletion threw exception", ex2);
-
如果任何一个拦截器返回false,直接跳出不执行目标方法
-
所有拦截器都返回true,才执行目标方法
-
方法执行完成后
mappedHandler.applyPostHandle(processedRequest, response, mv);
void applyPostHandle(HttpServletRequest request, HttpServletResponse response, @Nullable ModelAndView mv)
throws Exception {
for (int i = this.interceptorList.size() - 1; i >= 0; i--) {
HandlerInterceptor interceptor = this.interceptorList.get(i);
interceptor.postHandle(request, response, this.handler, mv);
- 前面的步骤有任何异常都会直接倒叙执行拦截器的afterCompletion方法
- 页面渲染完成以后也会倒叙执行拦截器的afterCompletion方法
SpringBoot源码自动配置原理SpringBoot的核心注解@SpringBootApplication@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Inherited@SpringBootConfiguration@EnableAutoConfiguration@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUS
能够实现帮助开发者快速的整合第三方框架(Spring、Mybatis、hibernate)
原理:Maven依赖封装整合和自定义starter.
完全去除XML配置,采用注解形式
原理:SpringBoot其实根据 Spring 体系原生的注解实现包装
不需要外部容器,内嵌入服务器(Tomcat) .
原理:Java语言创建tomcat服务器,让后将本地class文件交给tomcat加载。
案例:注解方式启动MVC将SpringMVC交给内部tomcat运行
首先在main函数中启动当前应用程序(SpringApplication启动)
创建SpringApplication对象(new SpringApplication()).在对象的构造方法中进行参数的初始化工作,最主要的是判断当前应用程序的类型以及初始化器和监听器,在此过程中会加载整个应用程序中的spring.factories文件,将文件的内容放在缓存对象中,方便后续获取,具体步骤如下:
配置resourceloader
判断当前应用程序的类型
(1)为什么导入dependency时不需要指定版本?
在springboot pom.xml文件中有两个核心依赖,分别是spring-boot-starter-parent和spring-boot-starter-web
先看spring-boot-starter-parent中的properties节点
工程的Java版本为 1.8 。
工程代码的编译源文件编码格式为 UTF-8
工程编译后的文件编码格式为 UTF-8
Maven打包编译的版本
再看Build节点,分别定义了resource和
@Import注解有三种用法我们知道,使用@Import是一种很好的导入Bean定义信息的方式
弊端: 但是使用这个@Import三种用法导入的,无法保证顺序,比如整合Mybatis时,我们有SqlSessionFactory,那么如果我们自己个性化配置的SqlSessionFactory就无法在这个默认的前面加载
Spring中使用了 DeferredImportSelector接口的方式,实现这个接口并标识@Import的类..
SpringBoot源码分析
1、Spring和springboot是关系是什么?
Springboot是spring就是最核心的产品之一(是spring的分支项目),当然就包含springmvc。springmvc 只是spring 处理web层请求的一个模块。
Springboot是构建在spring基础之上的一个产品,其主要目的就是简化spring框架中繁复的配置问题,用什么方式来解决的呢?
用注解和类完成的
无论使用spring还是springboot开发,其本质来说,springboot都是在做一
感谢您的提问,我可以回答您关于springboot源码学习计划的问题。
Spring Boot 是一个基于 Spring 框架的快速开发脚手架,它的设计理念是约定大于配置,可以帮助开发者快速搭建 Spring 应用程序。如果您想要学习 Spring Boot 的源码,可以先了解 Spring Framework 的基本原理和设计思想,这对于理解 Spring Boot 的实现原理非常有帮助。
建议您首先阅读 Spring Boot 官方文档,熟悉其核心概念和用法。然后可以下载 Spring Boot 的源码,通过调试和分析源码,深入理解 Spring Boot 的实现细节和原理。在此过程中,您可以关注 Spring Boot 启动流程、自动配置、条件化注解等关键点,深入掌握 Spring Boot 的核心功能和优化策略。
最后,我建议您加入 Spring Boot 社区,与其他开发者交流学习心得和经验,共同推动 Spring Boot 生态的发展。