文天大人 2017-12-25 09:01 采纳率: 60%
浏览 889
已结题

关于SpringMVC的ContextLoader类中的一个疑问

我一直不太明白,在initWebApplicationContext方法的第一行,

 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!");
        }

请问各位大佬,难道servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) 何时不等于null呢??为什么要判断一下不等于null呢?服务刚启动的时候,还有不等于null的时候吗?之前学习servlet的时候并没有太认真学,还请各位大神帮忙解释一下,在此感谢

  • 写回答

7条回答 默认 最新

  • jasondyoung 2017-12-25 09:07
    关注

    没看它抛异常的翻译嘛。
    不能初始化context,因为已经有一个root应用context存在。检查你的web.xml中是否有多个ContextLoader 定义 。

    评论

报告相同问题?