Spring的contextLoader详解
来源:互联网 发布:非线性优化计算方法pdf 编辑:程序博客网 时间:2024/06/06 08:57
public class ContextLoader {
public static final String CONTEXT_CLASS_PARAM = "contextClass";
//此处定义了spring配置文件的参数名称,和web.xml中的
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/dataAccessContext-IBatis.xml</param-value>
</context-param>
完全对应,这个名字是不可更改的
public static final String CONFIG_LOCATION_PARAM = "contextConfigLocation";
public static final String LOCATOR_FACTORY_SELECTOR_PARAM = "locatorFactorySelector";
public static final String LOCATOR_FACTORY_KEY_PARAM = "parentContextKey";
private static final String DEFAULT_STRATEGIES_PATH = "ContextLoader.properties";
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 {
ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.class);
defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);
}
catch (IOException ex) {
throw new IllegalStateException("Could not load 'ContextLoader.properties': " + ex.getMessage());
}
}
private final Log logger = LogFactory.getLog(ContextLoader.class);
/**
* The root WebApplicationContext instance that this loader manages.
*/
private WebApplicationContext context;
/**
* Holds BeanFactoryReference when loading parent factory via
* ContextSingletonBeanFactoryLocator.
*/
private BeanFactoryReference parentContextRef;
.......
protected WebApplicationContext createWebApplicationContext(
ServletContext servletContext, ApplicationContext parent) throws BeansException {
Class contextClass = determineContextClass(servletContext);
if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
throw new ApplicationContextException("Custom context class [" + contextClass.getName() +
"] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]");
}
ConfigurableWebApplicationContext wac =
(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
wac.setParent(parent);
wac.setServletContext(servletContext);
//这里getInitParameter()方法概述:public java.lang.String getInitParameter(java.lang.String name)返回上下文定义的变量的值,如果变量不存在,返回null。见ServletConfig.getInitParameter (java.lang.String)。
String configLocation = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
//最后使用configLocation初始化wac对象
if (configLocation != null) {
wac.setConfigLocations(StringUtils.tokenizeToStringArray(configLocation,
ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS));
}
wac.refresh();
return wac;
}
- Spring的contextLoader详解
- Spring-ContextLoader
- spring--contextLoader源码
- Spring源码解读:ContextLoader类
- Spring-web源码解析之ContextLoader
- 一头扎进Spring源码之ContextLoader
- ContextLoader中setContextInitializers(ApplicationContextInitializer<?>... initializers)的思考
- ContextLoader-api
- Under Spring Framework: No appenders could be found for logger (....ContextLoader)
- spring的事务处理详解
- 详解Spring的配置文件
- 详解Spring的配置文件
- 详解Spring的配置文件
- 详解Spring的配置文件
- 详解Spring的配置文件
- 详解Spring的配置文件
- spring的Ioc详解
- 详解Spring的配置文件
- 将输入句子中的大写字母变为小写
- Schema约束、Http协议、WebService服务学习笔记
- 文章标题
- Android HandlerThread 完全解析
- Hibernate 关联关系中toString引起的死循环
- Spring的contextLoader详解
- eclipse怎么查看class文件(源码)
- Android集成微信分享,由于分享的缩略图大于32K,而无法调起微信客户端
- String类详解(浅拷贝,深拷贝,引用计数,写时拷贝)
- 导入表编程-枚举导入表
- 【分享】360云盘不限速-达峰值v7.5.4.1240版
- Python实现图片转字符画
- 83. Remove Duplicates from Sorted List
- jmeter随笔(12)--定制json响应结果断言