Spring 框架 和 组件整理

312 阅读1分钟

Spring 框架思维导图 image.png

Spring 加载过程

image.png

Spring

BeanFactory 和ApplicationContext 区别?

BeanFactory 是bean 集合的工厂类,包含对bean 定义,实例化对象,并生成协作类之间关系,对bean 生命周期控制,调用客户端的初始化方法(initialization methods)和销毁方法(destruction methods)

ApplicationContext和bean Factory 一样有bean 定义/关联设置,根据请求分发bean,

还有其他功能:

1.支持国际化的文本消息

2.统一的资源文件的读取方式

3.已在监听器中注册的bean事件

ApplicationContext 实现的三种方式:

1.ClassPathXmlApplicationContext: 从classpath的从xml 配置文件中读取上下文,并生成上下文定义。

applicationContext context = new ClassPathXmlApplicationContext(“bean.xml”)

2.FileSystemXmlApplicationContext: 由文件系统中的xml 配置文件中读取上下文

ApplicationContext context = new FileSystemXmlApplicationConte

xt(“bean.xml”);

3.XmlWebApplicationContext: 由Web应用的XML文件读取上下文

4.AnnotationConfigApplicationContext (基于Java配置启动)

image.png