spring 技术内幕--IOC初始化过程深入之BeanDefinition的定位
来源:互联网 发布:淘宝收藏大师效果好么 编辑:程序博客网 时间:2024/06/05 20:29
FileSystemApplicationContext的继承体系:FileSystemXmlApplicationContext->AbstractXmlApplicationContext->AbstractRefreshableConfigApplicationContext->AbstractApplicationContext->DefaultResourceLoader->protected final void refreshBeanFactory() throws BeansException{//如果BeanFactory建立了,销毁并关闭BeanFactory if(hasBeanFactory()){ destroyFactory(); closeBeanFactory(); } //创建并设置持有DefaultListableBeanFactory的地方调用loadBeanDefinition再载入BeanDefinition的信息 try{ DefaultListableBeanFactory beanFactory=createBeanFactory(); beanFactory.setSerializationId(getId());customizeBeanFactory(beanFactory);loadBeanDefinitions(beanFactory);synchronized(this.beanFactoryMonitor){this.beanFactory=beanFactory;}}catch(IOException ex){throw new ApplicationContextException("IO error parsing XML document for"+getDisplayName(),ex);}}protected DefaultListableBeanFactory createBeanFactory(){return new DefaultListableBeanFactory(getInternalParentbeanFactory());}//使用BeanDefinitionReader载入Bean定义的地方。protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)throws IOException,BeansException;public int loadBeanDefinitions(String location,Set actualResources) throws BeanDefinitionStoreException{ //取得ResourceLoader,使用的是DefaultResourceLoader ResourceLoader resourceLoader=getResourceLoader(); if(resourceLoader==null){ throw new BeanDefinitionException("cant import bean definitions from location["+location+"]:no ResourecLoader available"); }//对Resource路径模式进行解析if(resourceLoader instanceOf ResourcePatternResolver){ try{//调用DefaultResourceLoader的getResource完成具体的Resource定位Resource[] res=((ResourcePatternresolver) resourceLoader).getResources(location);int loadCount=loadBeanDefinitions(resources);if(ACTUALrESOURCES==NULL){for(int i=0;i<resources.length;i++){actualResources.add(resources[i]);}}if(logger.isDebugEnabled()){logger.debug("Loaded"+loadcount+"bean definitions from location pattern["+location+"]");}return loadcount;}catch(IOException ex){throw new BeanDefinitionStoreException{"couldnt resolve bean definition resource pattern["+location+"],ex"}}else{//调用DefaultResourceLoader的getResource完成Resource的定位Resource resource=resourceLoader.getResource(location);int loadCount=loadBeanDefinitions(resource);if(actualResources!=null){actualResources.add(resource);return loadCount;}}} }
1.BeanDefinition的Resource定位:
ClassPathResource res=new ClassPathResource(“beans.xml”);
;相当于打水找到水源。
取得resource的具体过程:
public Resource getResource(String location){
}
路径模式是先找classpath路径的resource,再找url的resource,两者都没有,就用getResourceByPath(location);
0 0
- spring 技术内幕--IOC初始化过程深入之BeanDefinition的定位
- spring 技术内幕--IOC初始化过程深入之BeanDefinition的载入和解析1
- spring 技术内幕--IOC初始化之BeanDefinition的在IOC容器中的注册
- spring技术内幕笔记:IoC容器的初始化过程(3)- BeanDefinition的注册
- spring技术内幕笔记:IoC容器初始化过程(2)- BeanDefinition的载入
- Spring技术内幕之IOC容器的实现(02)-BeanDefinition的Resource定位
- Spring技术内幕之IOC容器的实现(01)-IOC容器初始化过程
- spring技术内幕笔记:IoC容器初始化过程(1)- Resource定位
- 5-spring源码3.2.18解读+spring技术内幕(关于BeanDefinition的定位)
- 深探spring系列-----ioc初始化(1)BeanDefinition的Resource定位
- 【Spring Framework 深入】—— IoC容器初始化 -> BeanDefinition的注册
- 读《Spring技术内幕》-总结3-IoC容器的初始化过程
- Spring IOC容器的初始化过程--资源定位
- Spring源码阅读之IoC容器初始化3 -- BeanDefinition在IoC容器中的注册
- spring技术内幕之IoC容器的实现
- Spring IOC学习心得之IOC容器的初始化过程
- spring 技术内幕--IOC
- spring技术内幕2-IOC定位Bean定义资源
- BNUOJ-4052-BT马
- MongoDB3.2中与DB数据库操作相关常用方法介绍
- iis配置站点,页面中的video 视频标签加载的视频无法播放或者无法加载的解决方法
- docker python api 安装配置
- 台湾中央大学认知神经科学研究所所长洪兰对于男女脑活动的比较
- spring 技术内幕--IOC初始化过程深入之BeanDefinition的定位
- 易语言
- 因为你,我想变得更好
- WCF与WebService的区别
- 修改了request ,存入mysql数据库仍乱码。。。
- 机器人控制入门
- IP地址分类
- Retrofit
- 《Windows API》01 简介