启动类ClassPathXmlApplicationContext
public ClassPathXmlApplicationContext(
String[] configLocations, boolean refresh, @Nullable ApplicationContext parent)
throws BeansException {
super(parent);
setConfigLocations(configLocations);
if (refresh) {
refresh();
}
}
其中的父类构造方法:
super(parent);
02
ClassPathXmlApplicationContext 继承 AbstractXmlApplicationContext:
public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext
AbstractXmlApplicationContext的构造方法:
public AbstractXmlApplicationContext(@Nullable ApplicationContext parent) {
super(parent);
}
03.AbstractXmlApplicationContext 继承 AbstractRefreshableConfigApplicationContext
AbstractRefreshableConfigApplicationContext的构造方法:
public AbstractRefreshableConfigApplicationContext(@Nullable ApplicationContext parent) {
super(parent);
}
04.AbstractRefreshableConfigApplicationContext 继承 AbstractRefreshableApplicationContext
AbstractRefreshableApplicationContext的构造方法:
public AbstractRefreshableApplicationContext(@Nullable ApplicationContext parent) {
super(parent);
}
05.AbstractRefreshableApplicationContext 继承 AbstractApplicationContext
AbstractApplicationContext的构造方法:
public AbstractApplicationContext(@Nullable ApplicationContext parent) {
this();
setParent(parent);
}
public AbstractApplicationContext() {
this.resourcePatternResolver = getResourcePatternResolver();
}
getResourcePatternResolver() 解析资源的函数,比如xml文件
protected ResourcePatternResolver getResourcePatternResolver() {
return new PathMatchingResourcePatternResolver(this);
}
/** 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);
/** Display name. */
private String displayName = ObjectUtils.identityToString(this);
/** Parent context. */
@Nullable
private ApplicationContext parent;
/** Environment used by this context. */
@Nullable
private ConfigurableEnvironment environment;
/** BeanFactoryPostProcessors to apply on refresh. */
private final List<BeanFactoryPostProcessor> beanFactoryPostProcessors = new ArrayList<>();
/** System time in milliseconds when this context started. */
private long startupDate;
/** Flag that indicates whether this context is currently active. */
private final AtomicBoolean active = new AtomicBoolean();
/** Flag that indicates whether this context has been closed already. */
private final AtomicBoolean closed = new AtomicBoolean();
/** Synchronization monitor for the "refresh" and "destroy". */
private final Object startupShutdownMonitor = new Object();
@Nullable
private Thread shutdownHook;
/** ResourcePatternResolver used by this context. */
private final ResourcePatternResolver resourcePatternResolver;
/** LifecycleProcessor for managing the lifecycle of beans within this context. */
@Nullable
private LifecycleProcessor lifecycleProcessor;
/** MessageSource we delegate our implementation of this interface to. */
@Nullable
private MessageSource messageSource;