org.springframework.web.context.support
Class WebApplicationContextUtils

java.lang.Object
  extended byorg.springframework.web.context.support.WebApplicationContextUtils

public abstract class WebApplicationContextUtils
extends java.lang.Object

Convenience methods to retrieve the root WebApplicationContext for a given ServletContext. This is e.g. useful for accessing a Spring context from within custom web views or Struts actions.

Version:
$Id: WebApplicationContextUtils.java,v 1.10 2004/03/22 10:32:17 jhoeller Exp $
Author:
Juergen Hoeller
See Also:
ContextLoader

Constructor Summary
WebApplicationContextUtils()
           
 
Method Summary
static WebApplicationContext getRequiredWebApplicationContext(javax.servlet.ServletContext sc)
          Find the root WebApplicationContext for this web app, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.
static WebApplicationContext getWebApplicationContext(javax.servlet.ServletContext sc)
          Find the root WebApplicationContext for this web app, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebApplicationContextUtils

public WebApplicationContextUtils()
Method Detail

getWebApplicationContext

public static WebApplicationContext getWebApplicationContext(javax.servlet.ServletContext sc)
Find the root WebApplicationContext for this web app, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.

Parameters:
sc - ServletContext to find the web application context for
Returns:
the root WebApplicationContext for this web app, or null if none
See Also:
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE

getRequiredWebApplicationContext

public static WebApplicationContext getRequiredWebApplicationContext(javax.servlet.ServletContext sc)
                                                              throws java.lang.IllegalStateException
Find the root WebApplicationContext for this web app, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.

Parameters:
sc - ServletContext to find the web application context for
Returns:
the root WebApplicationContext for this web app
Throws:
java.lang.IllegalStateException - if the root WebApplicationContext could not be found
See Also:
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE


Copyright (C) 2003-2004 The Spring Framework Project.