zoukankan      html  css  js  c++  java
  • spring源码分析 contextConfigLocation属性的位置

    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/config/application-context.xml
                /WEB-INF/config/cache-context.xml
                /WEB-INF/config/captcha-context.xml
                /WEB-INF/config/jeecms/jeecore-context.xml
                /WEB-INF/config/jeecms/jeecms-context.xml
                /WEB-INF/config/shiro-context.xml
                /WEB-INF/config/plug/**/*-context.xml
                /WEB-INF/config/quartz-task.xml
            </param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>

    spring项目中web.xml都会有这么写配置。

    ContextLoaderListener 初始化通过ContextLoaderListener.
    那么contextConfigLocation这个属性在哪呢。

    public class ContextLoaderListener extends ContextLoader implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
    initWebApplicationContext(event.getServletContext());
    }

    public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {
            if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
                throw new IllegalStateException(
                        "Cannot initialize context because there is already a root application context present - " +
                        "check whether you have multiple ContextLoader* definitions in your web.xml!");
            }
    
            Log logger = LogFactory.getLog(ContextLoader.class);
            servletContext.log("Initializing Spring root WebApplicationContext");
            if (logger.isInfoEnabled()) {
                logger.info("Root WebApplicationContext: initialization started");
            }
            long startTime = System.currentTimeMillis();
    
            try {
                // Store context in local instance variable, to guarantee that
                // it is available on ServletContext shutdown.
                if (this.context == null) {
                    this.context = createWebApplicationContext(servletContext);
    protected WebApplicationContext createWebApplicationContext(ServletContext sc) {
            Class<?> contextClass = determineContextClass(sc);
    protected Class<?> determineContextClass(ServletContext servletContext) {
            String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM);
            if (contextClassName != null) {
                try {
                    return ClassUtils.forName(contextClassName, ClassUtils.getDefaultClassLoader());
                }
                catch (ClassNotFoundException ex) {
                    throw new ApplicationContextException(
                            "Failed to load custom context class [" + contextClassName + "]", ex);
                }
            }
            else {
                contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName());

    public abstract class AbstractRefreshableWebApplicationContext extends AbstractRefreshableConfigApplicationContext
            implements ConfigurableWebApplicationContext, ThemeSource {
    public abstract class AbstractRefreshableConfigApplicationContext extends AbstractRefreshableApplicationContext
            implements BeanNameAware, InitializingBean {
    
        private String[] configLocations;

    ok,

    AbstractRefreshableConfigApplicationContext 。。。
  • 相关阅读:
    分享 | 自定义属于自己的U盘图标
    GIF工具 | 分享几个Gif相关工具
    XTU | 人工智能入门复习总结
    XTU | 物联网概论复习总结
    收纳箱2号 | 前端开发大全
    收纳箱1号 | GitHub Pages部署静态网页的一点私货
    博客 | 基于Travis CI实现Hexo在Github和Coding的同步自动化部署
    图床plus演示 | 图床及在线分享演示文稿工具
    css写实心正三角和倒三角
    React 多个className的写法
  • 原文地址:https://www.cnblogs.com/chywx/p/9354770.html
Copyright © 2011-2022 走看看