Apereo CAS 5.3 项目源码地址:https://github.com/apereo
CAS 系列详解:https://blog.youkuaiyun.com/makyan/column/info/36060
上一节内容:https://blog.youkuaiyun.com/makyan/article/details/88907349
本节继上一节内容讲解
四、Spring Boot自动加载的原理
在讲解CAS 5.3 Server 端自定义注册、修改密码、验证等功能之前,我们先来了解一下Spring Boot 自动加载的原理。
4.1. SpringBoot自动加载的原理:
SpringBoot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,将该配置文件中的配置载入到Spring容器。
4.2. 源码分析
SpringBoot在进行对象实例化时,使用的是SpringApplication,这是SpringBoot的入口程序,它通过run方法运行。
分析SpringApplication类的源码
public static void main(String[] args) throws Exception {
run(new Object[0], args);
}
查看run方法
public static ConfigurableApplicationContext run(Object[] sources, String[] args) {
return (new SpringApplication(sources)).run(args);
}
run方法只是利用自己的构造器,创建自己的一个对象,然后再调用run方法。
查看这个构造器SpringApplication(sources)
public SpringApplication(ResourceLoader resourceLoader, Object... sources) {
this.bannerMode = Mode.CONSOLE;
this.logStartupInfo = true;
this.addCommandLineProperties = true;
this.headless = true;
this.registerShutdownHook = true;
this.additionalProfiles = new HashSet();
this.resourceLoader = resourceLoader;
this.initialize(sources);
}
发现这个构造器里面调用了一个自己的initializa方法
查看initialize(sources) 方法