24 lines
945 B
Markdown
24 lines
945 B
Markdown
|
# 第一章启动
|
|||
|
|
|||
|
## 说明
|
|||
|
|
|||
|
1. 使用spring版本5.3.5
|
|||
|
2. 起始类ClassPathXmlApplicationContext,可以使用org.springframework.context.support.GenericApplicationContext自定义读取配置
|
|||
|
|
|||
|
```java
|
|||
|
GenericApplicationContext ctx = new GenericApplicationContext();
|
|||
|
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
|
|||
|
xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml"));
|
|||
|
PropertiesBeanDefinitionReader propReader = new PropertiesBeanDefinitionReader(ctx);
|
|||
|
propReader.loadBeanDefinitions(new ClassPathResource("otherBeans.properties"));
|
|||
|
ctx.refresh();
|
|||
|
MyBean myBean = (MyBean) ctx.getBean("myBean");
|
|||
|
```
|
|||
|
|
|||
|
## 解读ClassPathXmlApplicationContext
|
|||
|
|
|||
|
1. 从构造函数中,点击追踪父类默认加载:org.springframework.context.support.AbstractApplicationContext
|
|||
|
2. 加载构造函数中传入的参数(String... locations),循环处理路径locations
|
|||
|
3. 是否刷新加载到的内容
|
|||
|
|