技术开发 频道

初探spring applicationContext


IT168技术文档】 
    ==>contextLoader.determineContextClass(servletContext);
protected Class determineContextClass(ServletContext servletContext) throws ApplicationContextException { <span style="color:red;"> //获得需要实例化的CONTEXT类名,在web.xml中有设置,如果没有设置,那么为空 String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM); if (contextClassName != null) { try { return ClassUtils.forName(contextClassName); } catch (ClassNotFoundException ex) { throw new ApplicationContextException( "Failed to load custom context class [" + contextClassName + "]", ex); } } //如果在spring web.xml中没有设置context类位置,那么取得默认context else { //取得defaultStrategies配置文件中的WebApplicationContext属性 contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName()); try { return ClassUtils.forName(contextClassName); } catch (ClassNotFoundException ex) { throw new ApplicationContextException( "Failed to load default context class [" + contextClassName + "]", ex); } } </span> }
    SPRING上下文默认的策略是甚么呢? 
    ==>contextLoader.defaultStrategies
private static final Properties defaultStrategies; static { // Load default strategy implementations from properties file. // This is currently strictly internal and not meant to be customized // by application developers. try { <span style="color:red;"> //设置classpath为contextLoader同级目录 ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.class); //加载该目录下的所有properties文件 defaultStrategies = PropertiesLoaderUtils.loadProperties(resource); </span> } catch (IOException ex) { throw new IllegalStateException("Could not load 'ContextLoader.properties': " + ex.getMessage()); } }
0
相关文章