public abstract class WebApplicationObjectSupport extends ApplicationObjectSupport implements ServletContextAware
WebApplicationContext.
Provides getWebApplicationContext(), getServletContext(), and
getTempDir() accessors.
Note: It is generally recommended to use individual callback interfaces for the actual
callbacks needed. This broad base class is primarily intended for use within the framework,
in case of ServletContext access etc typically being needed.
SpringBeanAutowiringSupportlogger| Constructor and Description |
|---|
WebApplicationObjectSupport() |
| Modifier and Type | Method and Description |
|---|---|
protected ServletContext |
getServletContext()
Return the current ServletContext.
|
protected File |
getTempDir()
Return the temporary directory for the current web application,
as provided by the servlet container.
|
protected WebApplicationContext |
getWebApplicationContext()
Return the current application context as WebApplicationContext.
|
protected void |
initApplicationContext(ApplicationContext context)
Calls
initServletContext(javax.servlet.ServletContext) if the
given ApplicationContext is a WebApplicationContext. |
protected void |
initServletContext(ServletContext servletContext)
Subclasses may override this for custom initialization based
on the ServletContext that this application object runs in.
|
protected boolean |
isContextRequired()
Overrides the base class behavior to enforce running in an ApplicationContext.
|
void |
setServletContext(ServletContext servletContext)
Set the
ServletContext that this object runs in. |
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContextpublic final void setServletContext(ServletContext servletContext)
ServletContextAwareServletContext that this object runs in.
Invoked after population of normal bean properties but before an init
callback like InitializingBean's afterPropertiesSet or a
custom init-method. Invoked after ApplicationContextAware's
setApplicationContext.
setServletContext in interface ServletContextAwareservletContext - ServletContext object to be used by this objectInitializingBean.afterPropertiesSet(),
ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)protected boolean isContextRequired()
protected void initApplicationContext(ApplicationContext context)
initServletContext(javax.servlet.ServletContext) if the
given ApplicationContext is a WebApplicationContext.initApplicationContext in class ApplicationObjectSupportcontext - the containing ApplicationContextApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)protected void initServletContext(ServletContext servletContext)
The default implementation is empty. Called by
initApplicationContext(org.springframework.context.ApplicationContext)
as well as setServletContext(javax.servlet.ServletContext).
servletContext - the ServletContext that this application object runs in
(never null)@Nullable protected final WebApplicationContext getWebApplicationContext() throws IllegalStateException
NOTE: Only use this if you actually need to access
WebApplicationContext-specific functionality. Preferably use
getApplicationContext() or getServletContext()
else, to be able to run in non-WebApplicationContext environments as well.
IllegalStateException - if not running in a WebApplicationContextApplicationObjectSupport.getApplicationContext()@Nullable protected final ServletContext getServletContext() throws IllegalStateException
IllegalStateException - if not running within a required ServletContextisContextRequired()protected final File getTempDir() throws IllegalStateException
IllegalStateException - if not running within a ServletContextWebUtils.getTempDir(javax.servlet.ServletContext)