wac.refresh

public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
// Prepare this context for refreshing.
prepareRefresh();

// Tell the subclass to refresh the internal bean factory.
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();

// Prepare the bean factory for use in this context.
prepareBeanFactory(beanFactory);

try {
// Allows post-processing of the bean factory in context subclasses.
postProcessBeanFactory(beanFactory);

// Invoke factory processors registered as beans in the context.
invokeBeanFactoryPostProcessors(beanFactory);

// Register bean processors that intercept bean creation.
registerBeanPostProcessors(beanFactory);

// Initialize message source for this context.
initMessageSource();

// Initialize event multicaster for this context.
initApplicationEventMulticaster();

// Initialize other special beans in specific context subclasses.
onRefresh();

// Check for listener beans and register them.
registerListeners();

// Instantiate all remaining (non-lazy-init) singletons.详见下边分析
finishBeanFactoryInitialization(beanFactory);


// Last step: publish corresponding event.
finishRefresh();
}



prepareRefresh();中
this.startupDate = System.currentTimeMillis();记录开始时间
this.active = true;设定标志位true
/** Flag that indicates whether this context is currently active */


接下来
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();

在方法obtainFreshBeanFactory();中
protected ConfigurableListableBeanFactory obtainFreshBeanFactory() {
refreshBeanFactory();//设定setSerializationId(getId())与设定this.refreshed = true;
ConfigurableListableBeanFactory beanFactory = getBeanFactory();//返回GenericApplicationContext() 内的实例变量private final DefaultListableBeanFactory beanFactory;这个变量在类ConfigurableListableBeanFactory 的默认构造函数中进行了部分初始化
public GenericApplicationContext() {
this.beanFactory = new DefaultListableBeanFactory();
this.beanFactory.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
this.beanFactory.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver());
}
可以看到默认的beanFactory 是DefaultListableBeanFactory
if (logger.isDebugEnabled()) {
logger.debug("Bean factory for " + getDisplayName() + ": " + beanFactory);
}
return beanFactory;
}

// Instantiate all remaining (non-lazy-init) singletons.分析
finishBeanFactoryInitialization(beanFactory);

在这个方法中,会把定义为单例的bean进行初始化。
对于普通的bean,在初始化过程中,会在中间加入postbeanProcess处理。
对于配置为factorybean产生的bean,在初始话时,会进行判断,并调用配置的factorybean来产生bean。具体带后续分析

你可能感兴趣的:(refresh)