Spring 源码分析
来源:互联网 发布:珠宝设计软件下载 编辑:程序博客网 时间:2024/06/05 04:35
为了读懂spring源码,我是根据debug来分析的。
一切的起点就是ApplicationContext。
根据构造函数的各种调用最终调用的是这个构造函数。
public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent) throws BeansException { super(parent); setConfigLocations(configLocations); if (refresh) { refresh(); } }
到这里最终的方法就是refresh(),super只是做一些初始化工作,可以忽略。
以下是初始化发放做的事情:
DEBUG [main] - Adding [systemProperties] PropertySource with lowest search precedenceDEBUG [main] - Adding [systemEnvironment] PropertySource with lowest search precedenceDEBUG [main] - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
没有任何有用的信息,直接忽略。
setConfiguration()这是一个简单的赋值操作。
而refresh()放最终调用的是AbstractApplicationContext的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(); } catch (BeansException ex) { logger.warn("Exception encountered during context initialization - cancelling refresh attempt", ex); // Destroy already created singletons to avoid dangling resources. destroyBeans(); // Reset 'active' flag. cancelRefresh(ex); // Propagate exception to caller. throw ex; } } }
preparRefresh()的输出
Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@26eeda37: startup date [Sun May 01 19:02:10 CST 2016]; root of context hierarchy
// Tell the subclass to refresh the internal bean factory. ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
的输出:
DEBUG [main] - Loading bean definitionsDEBUG [main] - Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@26eeda37: org.springframework.beans.factory.support.DefaultListableBeanFactory@2582e0fc: defining beans [countryService,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,dataSource,sqlSessionFactory,tk.mybatis.spring.mapper.MapperScannerConfigurer#0]; root of factory hierarchy
我首先从这个方法开始分析:
// Invoke factory processors registered as beans in the context. invokeBeanFactoryPostProcessors(beanFactory);
调用注册在context里面的beanFactory中的方法
0 0
- Spring 源码分析:ApplicationContext
- Spring 源码分析:ApplicationContext- -
- [转贴] Spring源码分析
- Spring 源码分析
- spring jdbc 源码 分析
- Spring ContextLoaderListener源码分析
- spring学习方法源码分析
- Spring IOC源码分析
- spring源码分析
- Spring ContextLoaderListener源码分析 .
- spring事务管理源码分析
- spring学习方法源码分析
- Spring HttpInvoker源码分析
- spring源码分析概要
- spring部分源码分析
- Spring MVC源码分析
- Spring Security3源码分析
- spring-mvc3 源码分析
- 机房重构之报表
- Mac OS X下搭建NDK环境
- AJAX 是什么?
- for循环实现各种图形输出
- 沙盒、文件以及文件夹的操作
- Spring 源码分析
- ios拼图游戏(四)之触摸交换拼图
- 集合
- Unity3D在Project中添加Favorites快速搜索标签
- 深入理解Java内存模型——volatile
- poj 2975
- Dinic算法的原理与构造(转)
- HDU 5676 ztr loves lucky numbers【DFS】
- 嵌入式linux内核制作