Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.web.context.support
Class WebApplicationContextUtils

    java.lang.Object
      org.springframework.web.context.support.WebApplicationContextUtils

    public abstract class WebApplicationContextUtils

extends 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.

Note that there are more convenient ways of accessing the root context for many web frameworks, either part of Spring or available as external library. This helper class is just the most generic way to access the root context.

Author:
  Juergen Hoeller
See Also:
  `ContextLoader`, `FrameworkServlet`, `DispatcherServlet`, `ActionSupport`, `DelegatingActionProxy`, `FacesContextUtils`, `DelegatingVariableResolver`

Constructor Summary
`WebApplicationContextUtils()`

Method Summary
`static WebApplicationContext` | `getRequiredWebApplicationContext(ServletContext sc)` Find the root WebApplicationContext for this web application, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.
`static WebApplicationContext` | `getWebApplicationContext(ServletContext sc)` Find the root WebApplicationContext for this web application, 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(ServletContext sc)

  Find the root WebApplicationContext for this web application, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.

  Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.

  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(ServletContext sc)
                                                                  throws IllegalStateException

  Find the root WebApplicationContext for this web application, which is typically loaded via ContextLoaderListener or ContextLoaderServlet.

  Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.

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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2007 The Spring Framework.