PortletApplicationContextUtils.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:spring4-understanding 作者:
/**
 * Find the root {@link WebApplicationContext} for this web app, typically
 * loaded via {@link org.springframework.web.context.ContextLoaderListener}.
 * <p>Will rethrow an exception that happened on root context startup,
 * to differentiate between a failed context startup and no context at all.
 * @param pc PortletContext to find the web application context for
 * @return the root WebApplicationContext for this web app, or {@code null} if none
 * (typed to ApplicationContext to avoid a Servlet API dependency; can usually
 * be casted to WebApplicationContext, but there shouldn't be a need to)
 * @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
 */
public static ApplicationContext getWebApplicationContext(PortletContext pc) {
    Assert.notNull(pc, "PortletContext must not be null");
    Object attr = pc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    if (attr == null) {
        return null;
    }
    if (attr instanceof RuntimeException) {
        throw (RuntimeException) attr;
    }
    if (attr instanceof Error) {
        throw (Error) attr;
    }
    if (!(attr instanceof ApplicationContext)) {
        throw new IllegalStateException("Root context attribute is not of type WebApplicationContext: " + attr);
    }
    return (ApplicationContext) attr;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号