一、什么是Context
Spring Context从字面上翻译是上下文,不过我觉得这词语就是鸡肋,毫无意义,中国人对这个词语无感觉。更贴切的说法是运行时候的“当前场景”,还不太理解,对不对?那好吧,来看一个例子,ApplicationContext,就是应用程序运行时候的当前场景,如图所示:

包含了bean工厂、资源加载、事件发布、环境、消息资源几个,合起来就是上下文。
现在可以用大白话理解:一个程序运行起来以后,它的上下文就是bean工厂,资源加载、事件发布器、运行环境、消息资源的的集合。
二、模块包结构

主要包含了:缓存cache、context、jndi、remoting等,其中以Context最重要,我们只分析这个
三、Context包分析
主要接口:ApplicationContext、ApplicationListener、Lifecycle
子目录:annotation、event、support,其他可以先不看。
3.1)annotation目录:
@Bean、@ComponentScan、@Condition、@Configuration、@DependsOn、@Import、@ImportSelector、@Profile等,这些注解都是Spring最核心的。
3.2)event目录
核心接口:ApplicationEventMulticaster、EventListener
作用:Spring事件机制的类
3.3)support
核心类:AbstractApplicationContext、ClassPathXmlApplicationContext、DefaultLifecycleProcessor以及messageSource相关的类(不是我们重点关注的)
以上就是Spring Context模块核心的接口、类分析
网友评论