这里所说的核心容器,大家可以把它简单的理解为 ApplicationContext
,前面虽然已经用到过,但是并没有系统的介绍过,接下来咱们从以下几个问题入手来下容器的相关知识:
-
如何创建容器?
-
创建好容器后,如何从容器中获取bean对象?
-
容器类的层次结构是什么?
-
BeanFactory是什么?
一、环境准备
在解决上述问题之前,先来准备下环境:
-
创建一个Maven项目
-
pom.xml添加Spring的依赖
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.10.RELEASE</version> </dependency> </dependencies>
-
resources下添加applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http: