public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { prepareRefresh();//准备启动spring容器,设置容器的启动日期和活动标志 ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();//获得容器ApplicationContext的子类BeanFactory。步骤如下:如果已经有了BeanFactory就销毁它里面的单例Bean并关闭这个BeanFactory。2.创建一个新的BeanFactory。3.对这个BeanFactory进行定制(customize),如allowBeanDefinitionOverriding,allowCircularReferences。4.转载BeanDefinitions(读取配置文件,将xml转换成对应得BeanDefinition)。5.检查是否同时启动了两个BeanFactory。 prepareBeanFactory(beanFactory);//配置BeanFactory(就是将ApplicationContext的一些属性配置到BeanFactory上吧)。这里做了很多事情,可以看看其源码,比较重要的如设置classLoader;将BeanPostProcess注册到BeanFactory里。 try { // Allows post-processing of the bean factory in context subclasses. postProcessBeanFactory(beanFactory); invokeBeanFactoryPostProcessors(beanFactory);//触发BeanFactoryPostProcessors registerBeanPostProcessors(beanFactory);//触发BeanPostProcessors // 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(); finishBeanFactoryInitialization(beanFactory);//初始化单例的Bean,并将其保存起来。 // Last step: publish corresponding event. finishRefresh(); } catch (BeansException ex) { // Destroy already created singletons to avoid dangling resources. beanFactory.destroySingletons(); // Reset 'active' flag. cancelRefresh(ex); // Propagate exception to caller. throw ex; } } }
相关推荐
2013-3-20 22:22:46 org.springframework.context.support.AbstractApplicationContext refresh 信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c1f10e: display name [org....
AbstractApplicationContext.refresh(){ 1.为刷新准备此上下文 prepareRefresh(){ initPropertySources();//在上下文环境中初始化任何占位符属性源 getEnvironment().validateRequiredProperties();//验证所有...
n 源码分析-AbstractApplicationContext的refresh方法 n 源码分析-AbstractBeanFactory的doGetBean方法 l Spring Aop n 设计模式-代理模式 n 编程思想-AOP思想 n 基础应用-入门案例 n 基础应用-常用注解 n 高级应用-...
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext....
sping applicationcontext中的一些例子demo 关于AbstractApplicationContext 以及它的几个常用子类的一些demo
我们先创建一个类TestService,加上@Service和@Transactional注解,随便写一个保存数据的方法。 1.1.1注册BeanDefinition的阶段 xml扫描过后,发现把所有Bean定义打印出来,发现有一个bean叫做“ proxyTargetClass =...
[[03 08:58:22,466 INFO ] org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:511) - Refreshing WebApplicationContext for namespace 'hessian-...
AbstractApplicationContext AbstractApplicationEventMulticaster AbstractAspectJAdvice AbstractAspectJAdvisorFactory AbstractAspectJAdvisorFactory.AspectJAnnotation AbstractAspectJAdvisorFactory....