spring源码---XmlWebApplicationContext解析

public class XmlWebApplicationContext extends AbstractRefreshableWebApplicationContext {

//默认配置文件地址
public static final String DEFAULT_CONFIG_LOCATION = "/WEB-INF/applicationContext.xml";

//为名称空间构建配置位置的默认前缀
public static final String DEFAULT_CONFIG_LOCATION_PREFIX = "/WEB-INF/";
*//** Default suffix for building a config location for a namespace *//*
//为名称空间构建配置位置的默认后缀
public static final String DEFAULT_CONFIG_LOCATION_SUFFIX = ".xml";
//解析applicationContext.xml
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {

    //为给定的BeanFactory创建一个新的XmlBeanDefinitionReader
    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
    // Configure the bean definition reader with this context's
    //用这个上下文配置bean定义读取器
    // resource loading environment.
    //资源加载环境
    beanDefinitionReader.setEnvironment(getEnvironment());
    beanDefinitionReader.setResourceLoader(this);
    beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
     //允许子类提供读取器的自定义初始化
    initBeanDefinitionReader(beanDefinitionReader);
    //实际加载bean定义
    loadBeanDefinitions(beanDefinitionReader);
}
//初始化子类读取器构造函数
protected void initBeanDefinitionReader(XmlBeanDefinitionReader beanDefinitionReader) {
}
//实际意义得加载定义bean
protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws IOException {
    String[] configLocations = getConfigLocations();
    if (configLocations != null) {
        for (String configLocation : configLocations) {
            reader.loadBeanDefinitions(configLocation);
        }*
    }
}/
//获取默认配置文件地址
@Override
protected String[] getDefaultConfigLocations() {
    if (getNamespace() != null) {
        return new String[] {DEFAULT_CONFIG_LOCATION_PREFIX + getNamespace() + DEFAULT_CONFIG_LOCATION_SUFFIX};
    }
    else {
        return new String[] {DEFAULT_CONFIG_LOCATION};
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值