日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spring启动过程之源码跟踪(续beanfactory)--spring Debug

發(fā)布時間:2025/4/5 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring启动过程之源码跟踪(续beanfactory)--spring Debug 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.初始化過程

1 Resource res = new ClassPathResource("/applicationContext.xml"); 2 XmlBeanFactory factory = new XmlBeanFactory(res);

2.入門

1 /** 2 * Create a new XmlBeanFactory with the given input stream, 3 * which must be parsable using DOM. 4 * @param resource XML resource to load bean definitions from 5 * @param parentBeanFactory parent bean factory 6 * @throws BeansException in case of loading or parsing errors 7 */ 8 public XmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException { 9 super(parentBeanFactory); 10 this.reader.loadBeanDefinitions(resource); 11 }

3.讀取配置文件XmlBeanDefinitionReader.java

1 public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException { 2 Assert.notNull(encodedResource, "EncodedResource must not be null"); 3 if (logger.isInfoEnabled()) { 4 logger.info("Loading XML bean definitions from " + encodedResource.getResource()); 5 } 6 7 Set currentResources = (Set) this.resourcesCurrentlyBeingLoaded.get(); 8 if (currentResources == null) { 9 currentResources = new HashSet(4); 10 this.resourcesCurrentlyBeingLoaded.set(currentResources); 11 } 12 if (!currentResources.add(encodedResource)) { 13 throw new BeanDefinitionStoreException( 14 "Detected recursive loading of " + encodedResource + " - check your import definitions!"); 15 } 16 try { 17 InputStream inputStream = encodedResource.getResource().getInputStream(); 18 try { 19 InputSource inputSource = new InputSource(inputStream); 20 if (encodedResource.getEncoding() != null) { 21 inputSource.setEncoding(encodedResource.getEncoding()); 22 } 23 return doLoadBeanDefinitions(inputSource, encodedResource.getResource()); 24 } 25 finally { 26 inputStream.close(); 27 } 28 } 29 catch (IOException ex) { 30 throw new BeanDefinitionStoreException( 31 "IOException parsing XML document from " + encodedResource.getResource(), ex); 32 } 33 finally { 34 currentResources.remove(encodedResource); 35 if (currentResources.isEmpty()) { 36 this.resourcesCurrentlyBeingLoaded.set(null); 37 } 38 } 39 }

4.讀取方法DefaultBeanDefinitionDocumentReader.java

1 /** 2 * Parses bean definitions according to the "spring-beans" DTD. 3 * <p>Opens a DOM Document; then initializes the default settings 4 * specified at <code>&lt;beans&gt;</code> level; then parses 5 * the contained bean definitions. 6 */ 7 public void registerBeanDefinitions(Document doc, XmlReaderContext readerContext) { 8 this.readerContext = readerContext; 9 10 logger.debug("Loading bean definitions"); 11 Element root = doc.getDocumentElement(); 12 13 BeanDefinitionParserDelegate delegate = createHelper(readerContext, root); 14 15 preProcessXml(root); 16 parseBeanDefinitions(root, delegate); 17 postProcessXml(root); 18 }

?

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/archive/2013/03/12/2956187.html

總結(jié)

以上是生活随笔為你收集整理的spring启动过程之源码跟踪(续beanfactory)--spring Debug的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。