参考文章:http://blog.csdn.net/chjttony/article/details/6301523
IBM中国开发者社区:http://www.ibm.com/developerworks/cn/
AnnotationConfigApplicationContext
AnnotationConfigWebApplicationContext
基于注解的应用实现,提供注解的Reader和包或类扫描的Scanner
其中类.class和包名是其入参
classAnnotationConfigApplicationContext extends
GenericApplicationContext
public AnnotationConfigApplicationContext() {
this.reader =new AnnotatedBeanDefinitionReader(this);
this.scanner =newClassPathBeanDefinitionScanner(this);
}
通用的应用实现,其他实现一般会继承这个类
class GenericApplicationContextextends
AbstractApplicationContext implements BeanDefinitionRegistry
public GenericApplicationContext() {
this.beanFactory =new DefaultListableBeanFactory();
this.beanFactory.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
}
实现Bean的注册定义,提供删除、获取、判断的方法
interface BeanDefinitionRegistryextends AliasRegistry
对注册别名进行设置、获取、判断
interface AliasRegistry
Interface : ResourceLoader //资源加载
提供两个接口:
得到资源加载句柄:Resource getResource();和
得到类加载器:ClassLoader getClassLoader();
class DefaultResourceLoader implements ResourceLoader
Private ClassLoader classLoader;
public DefaultResourceLoader() {
this.classLoader = ClassUtils.getDefaultClassLoader();
}
Public ClassLoader getClassLoader(){
return (this.classLoader != null ?this.classLoader : ClassUtils.getDefaultClassLoader());
}
//实现父类的getResource接口
Resource getResource(String location){
//实现
}
使用模板方法设计模式,简单实现共同的上下文功能,需要具体的子类来实现它。对父类的一些接口的具体实现。
abstractclassAbstractApplicationContext extends DefaultResourceLoader
implements ConfigurableApplicationContext,DisposableBean
interface DisposableBean
提供destroy();接口,销毁Bean
提供一个基于配置的Application的全面的应用接口
提供一些环境变量,设置和判断当前应用状态的接口
interface ConfigurableApplicationContext
extends ApplicationContext,Lifecycle
interface Lifecycle
提供控制周期的开始void start(),停止void stop(),现在的状态boolean isRunning(); 此典型的用例是控制异步处理
核心接口,对整个的Application在做控制
interfaceApplicationContext extends EnvironmentCapable,
ListableBeanFactory, HierarchicalBeanFactory,MessageSource,
ApplicationEventPublisher, ResourcePatternResolver
资源文件匹配解析
Interface ResourcePatternResolver extends ResourceLoader
封装事件的发布功能,为ApplicationContext的超级接口
interface ApplicationEventPubliser
void publishEvent(ApplicationEvent event);
对消息进行封装,支持参数化和国际化
interfaceMessageSource
提供获取父类的BeanFactory的方法
interface HierarchicalBeanFactoryextends BeanFactory
核心Bean工厂类,提供获取Bean的方法 Object getBean(String name)
是否是单例singleton,是否为原型Prototype;
操作别名getAliases(String Name)
interface BeanFactory
监听和预加载Bean实例;提供了获取带注解标签类的Map集合,根据名字获取Bean的定义等
interface ListableBeanFactoryextendsBeanFactory
获取Environment 环境变量。getEnviroment();
interface EnvironmentCapable