📘

ApplicationContext

ClassPathXmlApplicationContext

使用ApplicationContext解析XML文件
 
public class BeanFactoryDemo { public static void main(String[] args) { ApplicationContext alc = new ClassPathXmlApplicationContext("applicationContext.xml"); Student stu = (Student) alc.getBean("stu"); System.out.println(stu.getName()); } }
ClassPathXmlApplicationContext构造根据传入的xml文件,进行解析

ClassPathXmlApplicationContext的构造

notion image
notion image
 
notion image
 
getResourcePatternResolver 方法获取路径资源匹配的解析器
notion image
返回上一级的setParent()
notion image
将父环境的环境信息和子环境信息进行合并
notion image
 

ClassPathXmlApplicationContext设置配置地址

notion image
拿到之前我们传入的文件数组,遍历去解析每一个路径
notion image
notion image
解析 $的占位符号,用相关属性值去替换变量
notion image

refresh

notion image
refresh
 

Bean加载

Bean加载