spring Context 创建
? 使用spring框架的时候,在web.xml的配置文件中都会加入如下注释:
??
? ? 首先会进入方法:createWebApplicationContext()
?
??
? 当前方法会进入determineContextClass()方法
?
??
? ? 在web.xml中我很少会配置contextClass这个配置项,所以代码会走分支2,defaultStrategies的内容是什么呢?
? ? 在ContextLoader有如下代码
? ??DEFAULT_STRATEGIES_PATH为ContextLoader.properties,即是org.springframework.web.ContextLoader.properties
? ?ContextLoader.properties内容为:
? ?
? ? ? protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) {// The application context id is still set to its original default value// -> assign a more useful id based on available informationString idParam = sc.getInitParameter(CONTEXT_ID_PARAM); //设置idif (idParam != null) {wac.setId(idParam);}else {// Generate default id...if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {// Servlet <= 2.4: resort to name specified in web.xml, if any.wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +ObjectUtils.getDisplayString(sc.getServletContextName()));}else {wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +ObjectUtils.getDisplayString(sc.getContextPath()));}}}wac.setServletContext(sc); //CONFIG_LOCATION_PARAM即是:“contextConfigLocation”即web.xml配置的contextConfigLocation,即spring配置文件的位置String initParameter = sc.getInitParameter(CONFIG_LOCATION_PARAM);if (initParameter != null) {wac.setConfigLocation(initParameter);}customizeContext(sc, wac);wac.refresh();}? ?customizeContext(sc, wac);和wac.refresh();做了什么? 待续...
?
?