第一篇:Configuration-basic 之Spring对注解的处理【AnnotationConfigApplicationContext 】深度剖析

参考文章: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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值