spring启动过程之源码跟踪(中)--spring Debug
来源:互联网 发布:php datetime 时区 编辑:程序博客网 时间:2024/06/01 23:12
上节我们debug到
1 // Tell the subclass to refresh the internal bean factory.2 ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
我们继续debug 下一步:配置beanfactory的上下文
1 /** 2 * Configure the factory's standard context characteristics, 3 * such as the context's ClassLoader and post-processors. 4 * @param beanFactory the BeanFactory to configure 5 */ 6 protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) { 7 // Tell the internal bean factory to use the context's class loader. 8 beanFactory.setBeanClassLoader(getClassLoader()); 9 10 // Populate the bean factory with context-specific resource editors.11 beanFactory.addPropertyEditorRegistrar(new ResourceEditorRegistrar(this));12 13 // Configure the bean factory with context callbacks.14 beanFactory.addBeanPostProcessor(new ApplicationContextAwareProcessor(this));15 beanFactory.ignoreDependencyInterface(ResourceLoaderAware.class);16 beanFactory.ignoreDependencyInterface(ApplicationEventPublisherAware.class);17 beanFactory.ignoreDependencyInterface(MessageSourceAware.class);18 beanFactory.ignoreDependencyInterface(ApplicationContextAware.class);19 20 // BeanFactory interface not registered as resolvable type in a plain factory.21 // MessageSource registered (and found for autowiring) as a bean.22 beanFactory.registerResolvableDependency(BeanFactory.class, beanFactory);23 beanFactory.registerResolvableDependency(ResourceLoader.class, this);24 beanFactory.registerResolvableDependency(ApplicationEventPublisher.class, this);25 beanFactory.registerResolvableDependency(ApplicationContext.class, this);26 27 // Detect a LoadTimeWeaver and prepare for weaving, if found.28 if (beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME) && JdkVersion.isAtLeastJava15()) {29 // Register the (JDK 1.5 specific) LoadTimeWeaverAwareProcessor.30 try {31 Class ltwapClass = ClassUtils.forName(32 "org.springframework.context.weaving.LoadTimeWeaverAwareProcessor",33 AbstractApplicationContext.class.getClassLoader());34 BeanPostProcessor ltwap = (BeanPostProcessor) BeanUtils.instantiateClass(ltwapClass);35 ((BeanFactoryAware) ltwap).setBeanFactory(beanFactory);36 beanFactory.addBeanPostProcessor(ltwap);37 }38 catch (ClassNotFoundException ex) {39 throw new IllegalStateException("Spring's LoadTimeWeaverAwareProcessor class is not available");40 }41 // Set a temporary ClassLoader for type matching.42 beanFactory.setTempClassLoader(new ContextTypeMatchClassLoader(beanFactory.getBeanClassLoader()));43 }44 }
下面是下一步要debug的内容:
// 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();
初始化singletonbean(DefaultListableBeanFactory.java#preInstantiateSingletons())
1 public void preInstantiateSingletons() throws BeansException { 2 if (this.logger.isInfoEnabled()) { 3 this.logger.info("Pre-instantiating singletons in " + this); 4 } 5 6 synchronized (this.beanDefinitionMap) { 7 for (Iterator it = this.beanDefinitionNames.iterator(); it.hasNext();) { 8 String beanName = (String) it.next(); 9 RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);10 if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {11 if (isFactoryBean(beanName)) {12 FactoryBean factory = (FactoryBean) getBean(FACTORY_BEAN_PREFIX + beanName);13 if (factory instanceof SmartFactoryBean && ((SmartFactoryBean) factory).isEagerInit()) {14 getBean(beanName);15 }16 }17 else {18 getBean(beanName);19 }20 }21 }22 }23 }
结束动作:发布事件
1 public void publishEvent(ApplicationEvent event) { 2 Assert.notNull(event, "Event must not be null"); 3 if (logger.isTraceEnabled()) { 4 logger.trace("Publishing event in context [" + getId() + "]: " + event); 5 } 6 getApplicationEventMulticaster().multicastEvent(event); 7 if (this.parent != null) { 8 this.parent.publishEvent(event); 9 }10 }
- spring启动过程之源码跟踪(中)--spring Debug
- spring启动过程之源码跟踪(上)--spring Debug
- spring启动过程之源码跟踪(下)--spring Debug
- spring启动过程之源码跟踪(下)--spring Debug
- spring启动过程之源码跟踪(上)--spring Debug
- spring启动过程之源码跟踪(续beanfactory)--spring Debug
- spring启动过程之源码跟踪(小结bean的生命周期)--spring Debug
- Spring源码-启动过程
- 跟踪Spring源码(一)
- Spring 初始化过程跟踪
- spring-@Profile源码跟踪
- spring源码之spring启动一
- spring源码之spring启动二
- spring源码之spring启动三
- 【spring源码分析】之启动
- 【Spring启动过程分析】(2)源码分析
- Spring Boot启动过程源码分析(二)事件监听器
- Spring Framework源码读取-ContextLoaderListener启动过程
- ubuntu 上samba创建共享组目录
- sql server监控
- PHP mysql 一些判断
- 收缩事务日志
- spring启动过程之源码跟踪(上)--spring Debug
- spring启动过程之源码跟踪(中)--spring Debug
- c# webservice生成客户端及使用时碰到decimal类型时的特殊处理
- spring启动过程之源码跟踪(下)--spring Debug
- spring启动过程之源码跟踪(续beanfactory)--spring Debug
- spring启动过程之源码跟踪(小结bean的生命周期)--spring Debug
- JavaScript比较将变量变成数字类型比较大小
- 如何手动卸载 SQL Server 2005 实例(官方)
- spring aop小结(概念解析)
- Aop获取bean的过程---spring debug