前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >spring源码分析 contextConfigLocation属性的位置

spring源码分析 contextConfigLocation属性的位置

作者头像
陈灬大灬海
发布2018-09-12 15:38:19
1.7K0
发布2018-09-12 15:38:19
举报
代码语言:javascript
复制
<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都会有这么写配置。

代码语言:javascript
复制
ContextLoaderListener 初始化通过ContextLoaderListener.
那么contextConfigLocation这个属性在哪呢。
代码语言:javascript
复制
public class ContextLoaderListener extends ContextLoader implements ServletContextListener {

代码语言:javascript
复制
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);
代码语言:javascript
复制
protected WebApplicationContext createWebApplicationContext(ServletContext sc) {
        Class<?> contextClass = determineContextClass(sc);
代码语言:javascript
复制
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());
代码语言:javascript
复制
public abstract class AbstractRefreshableWebApplicationContext extends AbstractRefreshableConfigApplicationContext
        implements ConfigurableWebApplicationContext, ThemeSource {
代码语言:javascript
复制
public abstract class AbstractRefreshableConfigApplicationContext extends AbstractRefreshableApplicationContext
        implements BeanNameAware, InitializingBean {

    private String[] configLocations;

ok,

代码语言:javascript
复制
AbstractRefreshableConfigApplicationContext 。。。
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-07-23 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档