程序员下忍勇敢的进入了Applicationcontext的奇幻世界

前几天找了几家小公司的工作,所有的公司都给了我上班通知,选了一家,觉得及其没有希望,于是,继续进行我喜欢的Spring源码研究,前几天看了一些关于Resource,ResourceLoader,Reader,之类的蓝领类,那么今天终于想看看SpringIoc的核心类,所谓程序上下文,ApplicationContext,那么我要开始组装了。

public abstract class AbstractApplicationContext extends DefaultResourceLoader
  implements ConfigurableApplicationContext, DisposableBean

这个是AbstarctApplicationContext,这个类实现了两个接口--ConfigurableApplicationContext,DisposableBean ,用来实现上下文的可配置以及Bean的可配置,继承了一个资源加载器,DefaultResourceLoader,主要用来加载资源并对后续的各种配置操作提供基础。

    以下属性都是在factory中的名称。

/**
  * Name of the MessageSource bean in the factory.
  * If none is supplied, message resolution is delegated to the parent.
  * @see MessageSource
  */
 public static final String MESSAGE_SOURCE_BEAN_NAME = "messageSource";

 定义了一个统一的信息资源名称,messageSource。

 /**
  * Name of the LifecycleProcessor bean in the factory.
  * If none is supplied, a DefaultLifecycleProcessor is used.
  * @see org.springframework.context.LifecycleProcessor
  * @see org.springframework.context.support.DefaultLifecycleProcessor
  */
 public static final String LIFECYCLE_PROCESSOR_BEAN_NAME = "lifecycleProcessor";

 定义了一个统一的生命周期处理工具Bean的名称,lifecycleProcessor。

 /**
  * Name of the ApplicationEventMulticaster bean in the factory.
  * If none is supplied, a default SimpleApplicationEventMulticaster is used.
  * @see org.springframework.context.event.ApplicationEventMulticaster
  * @see org.springframework.context.event.SimpleApplicationEventMulticaster
  */
 public static final String APPLICATION_EVENT_MULTICASTER_BEAN_NAME = "applicationEventMulticaster";

定义其一个上下文事件的多路广播名称,applicationEventMulticaster。

 static {
  // Eagerly load the ContextClosedEvent class to avoid weird classloader issues
  // on application shutdown in WebLogic 8.1. (Reported by Dustin Woods.)
  ContextClosedEvent.class.getName();
 }

急迫的加载了ContextClosedEvent的类名称,在WebLogic 8.1中程序关闭的时候会出现怪异的类加载问题,这个bug是Dustin Woods报告的(他是谁呢?)

 /** Logger used by this class. Available to subclasses. */
 protected final Log logger = LogFactory.getLog(getClass());

子类和其公用的日志服务。

/** Unique id for this context, if any */
 private String id = ObjectUtils.identityToString(this);

每一次实例化这个类都会生成一个唯一的id,用来识别上下文,在容器中。

/** Display name */
 private String displayName = ObjectUtils.identityToString(this);

又一个唯一的id,用来作为显示的名称。

/** Parent context */
 private ApplicationContext parent;

一个弗雷的引用,要用到父类的一些可用功能,比如说转型之类

/** BeanFactoryPostProcessors to apply on refresh */
 private final List<BeanFactoryPostProcessor> beanFactoryPostProcessors =
   new ArrayList<BeanFactoryPostProcessor>();

bean工厂的后处理器,用来申请refresh服务。还是一个集合,看类同一时间会存在很多的后处理器服务类,按需索取吧。

/** System time in milliseconds when this context started */
 private long startupDate;

 上下文开始运行的系统毫秒级时间。

/** Flag that indicates whether this context is currently active */
 private boolean active = false;

 上下文是否活动的一个标志字段。

/** Flag that indicates whether this context has been closed already */
 private boolean closed = false;

 上下文是否关闭了的标志字段。

/** Synchronization monitor for the "active" flag */
 private final Object activeMonitor = new Object();

上下文是否是活动的一个线程安全型监视器。

/** Synchronization monitor for the "refresh" and "destroy" */
 private final Object startupShutdownMonitor = new Object();

refresh和destroy动作的线程安全型监视器。

/** Reference to the JVM shutdown hook, if registered */
 private Thread shutdownHook;

一个来自JVM虚拟机关闭时候的钩子,如果已经注册此钩子,hook,连带动作的载体。

/** ResourcePatternResolver used by this context */
 private ResourcePatternResolver resourcePatternResolver;

上下文所用的Resource按模式分解解决方案类。

/** LifecycleProcessor for managing the lifecycle of beans within this context */
 private LifecycleProcessor lifecycleProcessor;

管理生命周期的具体负责类,LifecycleProcessor。

/** MessageSource we delegate our implementation of this interface to */
 private MessageSource messageSource;

代表针对MessageSource接口的我们的具体实现,有很多写好的。

/** Helper class used in event publishing */
 private ApplicationEventMulticaster applicationEventMulticaster;

时间发布时候的帮助类,多路广播。

/** Statically specified listeners */
 private Set<ApplicationListener<?>> applicationListeners = new LinkedHashSet<ApplicationListener<?>>();

静态的监听容器,为什么是静态的?

/** Environment used by this context; initialized by {@link #createEnvironment()} */
 private ConfigurableEnvironment environment;

上下文环境,自然环境,createEnvironment()是造物主。

/**
  * Create a new AbstractApplicationContext with no parent.
  */
 public AbstractApplicationContext() {
  this(null);
 }
 /**
  * Create a new AbstractApplicationContext with the given parent context.
  * @param parent the parent context
  */
 public AbstractApplicationContext(ApplicationContext parent) {
  this.parent = parent;
  this.resourcePatternResolver = getResourcePatternResolver();
  this.environment = this.createEnvironment();
 }

填满属性或者不作任何操作,实例化的时候类可能是孤立的,并不一定存在实际的父类实例,我们也可以给出一个引用,具体使用再行研究。

转载于:https://my.oschina.net/stuspring/blog/475197

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值