public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("test.xml");
User user = applicationContext.getBean(User.class);
System.out.println(user.getName());
}
@Override
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
StartupStep contextRefresh = this.applicationStartup.start("spring.context.refresh");
// Prepare this context for refreshing.
// 准备工作
prepareRefresh();
// Tell the subclass to refresh the internal bean factory.
// 创建默认的Bean工厂 根据配置文件生成BeanDefinitions
**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);
StartupStep beanPostProcess = this.applicationStartup.start("spring.context.beans.post-process");
// Invoke factory processors registered as beans in the context.
invokeBeanFactoryPostProcessors(beanFactory);
// Register bean processors that intercept bean creation.
registerBeanPostProcessors(beanFactory);
beanPostProcess.end();
// Initialize message source for this context.
initMessageSource();
// Initialize event multicaster for this context.
配置文件加载代码调用链Main方法 public static void main(String[] args) { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("test.xml"); User user = applicationContext.getBean(User.class); System.out.println(user.g