WebApplicationContext for
a given ServletContext. This is useful for programmatically accessing
a Spring application context from within custom web views or MVC actions.
Note that there are more convenient ways of accessing the root context for many web frameworks, either part of Spring or available as an external library. This helper class is just the most generic way to access the root context.
org.springframework.web.context.ContextLoader , org.springframework.web.servlet.FrameworkServlet , org.springframework.web.servlet.DispatcherServlet , org.springframework.web.jsf.FacesContextUtils , org.springframework.web.jsf.el.SpringBeanFacesELResolver
| Modifier and Type | Class and Description |
|---|---|
| private static class | WebApplicationContextUtils.FacesDependencyRegistrar
Inner class to avoid hard-coded JSF dependency. |
| private static class | WebApplicationContextUtils.RequestObjectFactory
Factory that exposes the current request object on demand. |
| private static class | WebApplicationContextUtils.ResponseObjectFactory
Factory that exposes the current response object on demand. |
| private static class | WebApplicationContextUtils.SessionObjectFactory
Factory that exposes the current session object on demand. |
| private static class | WebApplicationContextUtils.WebRequestObjectFactory
Factory that exposes the current WebRequest object on demand. |
| Modifier and Type | Field and Description |
|---|---|
| private static final boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static ServletRequestAttributes | currentRequestAttributes()
Return the current RequestAttributes instance as ServletRequestAttributes. |
| public static WebApplicationContext | Returns: the desired WebApplicationContext for this web app, ornull if nonethe ServletContext to find the web application context for sc)Find a unique |
| public static WebApplicationContext | Returns: the root WebApplicationContext for this web appthe ServletContext to find the web application context for sc)Find the root |
| public static WebApplicationContext | Returns: the root WebApplicationContext for this web app, ornull if nonethe ServletContext to find the web application context for sc)Find the root |
| public static WebApplicationContext | Returns: the desired WebApplicationContext for this web app, ornull if nonethe ServletContext to find the web application context for sc, String the name of the ServletContext attribute to look for attrName)Find a custom |
| public static void | initServletPropertySources(MutablePropertySources propertySources, ServletContext servletContext)
Convenient variant of |
| public static void | initServletPropertySources(MutablePropertySources
the sources, ServletContext MutablePropertySources to initialize (must not
be null)the current servletContext, ServletConfig ServletContext (ignored if null
or if the servlet context property source has already been initialized)the current servletConfig)ServletConfig (ignored if null
or if the servlet config property source has already been initialized)Replace |
| public static void | registerEnvironmentBeans(ConfigurableListableBeanFactory
the BeanFactory to configure bf, ServletContext the ServletContext that we're running within sc)Register web-specific environment beans ("contextParameters", "contextAttributes") with the given BeanFactory, as used by the WebApplicationContext. |
| public static void | registerEnvironmentBeans(ConfigurableListableBeanFactory
the BeanFactory to configure bf, ServletContext the ServletContext that we're running within servletContext, ServletConfig the ServletConfig servletConfig)Register web-specific environment beans ("contextParameters", "contextAttributes") with the given BeanFactory, as used by the WebApplicationContext. |
| public static void | registerWebApplicationScopes(ConfigurableListableBeanFactory
the BeanFactory to configure beanFactory)Register web-specific scopes ("request", "session", "globalSession") with the given BeanFactory, as used by the WebApplicationContext. |
| public static void | registerWebApplicationScopes(ConfigurableListableBeanFactory
the BeanFactory to configure beanFactory, ServletContext the ServletContext that we're running within sc)Register web-specific scopes ("request", "session", "globalSession", "application") with the given BeanFactory, as used by the WebApplicationContext. |
| jsfPresent | back to summary |
|---|---|
| private static final boolean jsfPresent | |
| WebApplicationContextUtils | back to summary |
|---|---|
| public WebApplicationContextUtils() | |
| currentRequestAttributes | back to summary |
|---|---|
| private static ServletRequestAttributes currentRequestAttributes() Return the current RequestAttributes instance as ServletRequestAttributes. | |
| findWebApplicationContext | back to summary |
|---|---|
| public static WebApplicationContext findWebApplicationContext(ServletContext sc) Find a unique Note that
| |
| getRequiredWebApplicationContext | back to summary |
|---|---|
| public static WebApplicationContext getRequiredWebApplicationContext(ServletContext sc) throws IllegalStateException Find the root Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.
| |
| getWebApplicationContext | back to summary |
|---|---|
| public static WebApplicationContext getWebApplicationContext(ServletContext sc) Find the root Will rethrow an exception that happened on root context startup, to differentiate between a failed context startup and no context at all.
| |
| getWebApplicationContext | back to summary |
|---|---|
| public static WebApplicationContext getWebApplicationContext(ServletContext sc, String attrName) Find a custom
| |
| initServletPropertySources | back to summary |
|---|---|
| public static void initServletPropertySources(MutablePropertySources propertySources, ServletContext servletContext) Convenient variant of | |
| initServletPropertySources | back to summary |
|---|---|
| public static void initServletPropertySources(MutablePropertySources sources, ServletContext servletContext, ServletConfig servletConfig) Replace This method is idempotent with respect to the fact it may be called any number of times but will perform replacement of stub property sources with their corresponding actual property sources once and only once.
| |
| registerEnvironmentBeans | back to summary |
|---|---|
| public static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, ServletContext sc) Register web-specific environment beans ("contextParameters", "contextAttributes") with the given BeanFactory, as used by the WebApplicationContext.
| |
| registerEnvironmentBeans | back to summary |
|---|---|
| public static void registerEnvironmentBeans(ConfigurableListableBeanFactory bf, ServletContext servletContext, ServletConfig servletConfig) Register web-specific environment beans ("contextParameters", "contextAttributes") with the given BeanFactory, as used by the WebApplicationContext.
| |
| registerWebApplicationScopes | back to summary |
|---|---|
| public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory) Register web-specific scopes ("request", "session", "globalSession") with the given BeanFactory, as used by the WebApplicationContext.
| |
| registerWebApplicationScopes | back to summary |
|---|---|
| public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory, ServletContext sc) Register web-specific scopes ("request", "session", "globalSession", "application") with the given BeanFactory, as used by the WebApplicationContext.
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static void |
| FacesDependencyRegistrar | back to summary |
|---|---|
| private FacesDependencyRegistrar() | |
| registerFacesDependencies | back to summary |
|---|---|
| public static void registerFacesDependencies(ConfigurableListableBeanFactory beanFactory) | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public ServletRequest | getObject()
Implements org. |
| public String |
| RequestObjectFactory | back to summary |
|---|---|
| private RequestObjectFactory() | |
| getObject | back to summary |
|---|---|
| public ServletRequest getObject() Implements org. Doc from org. Return an instance (possibly shared or independent) of the object managed by this factory.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public ServletResponse | getObject()
Implements org. |
| public String |
| ResponseObjectFactory | back to summary |
|---|---|
| private ResponseObjectFactory() | |
| getObject | back to summary |
|---|---|
| public ServletResponse getObject() Implements org. Doc from org. Return an instance (possibly shared or independent) of the object managed by this factory.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public HttpSession | getObject()
Implements org. |
| public String |
| SessionObjectFactory | back to summary |
|---|---|
| private SessionObjectFactory() | |
| getObject | back to summary |
|---|---|
| public HttpSession getObject() Implements org. Doc from org. Return an instance (possibly shared or independent) of the object managed by this factory.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public WebRequest | getObject()
Implements org. |
| public String |
| WebRequestObjectFactory | back to summary |
|---|---|
| private WebRequestObjectFactory() | |
| getObject | back to summary |
|---|---|
| public WebRequest getObject() Implements org. Doc from org. Return an instance (possibly shared or independent) of the object managed by this factory.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |