首页 > 编程语言 > 详细

Spring 源码解析(二)加载配置文件2

时间:2018-03-30 18:11:10      阅读:238      评论:0      收藏:0      [点我收藏+]

接上一章,我们来具体分析下configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc)方法

 //org.springframework.web.context.ContextLoader.class
1
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { 2 if (ObjectUtils.identityToString(wac).equals(wac.getId())) { 3 // The application context id is still set to its original default value 4 // -> assign a more useful id based on available information 5 String idParam = sc.getInitParameter(CONTEXT_ID_PARAM); 6 if (idParam != null) { 7 wac.setId(idParam); 8 } 9 else { 10 // Generate default id... 11 wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + 12 ObjectUtils.getDisplayString(sc.getContextPath())); 13 } 14 } 15 16 wac.setServletContext(sc); 17 String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM); 18 if (configLocationParam != null) { 19 wac.setConfigLocation(configLocationParam); 20 } 21 22 // The wac environment‘s #initPropertySources will be called in any case when the context 23 // is refreshed; do it eagerly here to ensure servlet property sources are in place for 24 // use in any post-processing or initialization that occurs below prior to #refresh 25 ConfigurableEnvironment env = wac.getEnvironment(); 26 if (env instanceof ConfigurableWebEnvironment) { 27 ((ConfigurableWebEnvironment) env).initPropertySources(sc, null); 28 } 29 30 customizeContext(sc, wac); 31 wac.refresh(); 32 }

 

Spring 源码解析(二)加载配置文件2

原文:https://www.cnblogs.com/jintian315/p/8676357.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!