Top Description Fields Constructors Methods
org.springframework.web.context.support

public abstract Class WebApplicationObjectSupport

extends ApplicationObjectSupport
implements ServletContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.web.context.ServletContextAware, org.springframework.beans.factory.Aware
Imports
java.io.File, jakarta.servlet.ServletContext, org.springframework.context.ApplicationContext, org.springframework.context.support.ApplicationObjectSupport, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.context.ServletContextAware, .WebApplicationContext, org.springframework.web.util.WebUtils

Convenient superclass for application objects running in a 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.

Author
Juergen Hoeller
Since
28.08.2003
See Also
SpringBeanAutowiringSupport

Field Summary

Modifier and TypeField and Description
private ServletContext
Inherited from org.springframework.context.support.ApplicationObjectSupport:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected final ServletContext
getServletContext()

Return the current ServletContext.

protected final File

Returns:

the File representing the temporary directory
getTempDir
()

Return the temporary directory for the current web application, as provided by the servlet container.

protected final WebApplicationContext
getWebApplicationContext()

Return the current application context as WebApplicationContext.

protected void
protected void
initServletContext(ServletContext
the ServletContext that this application object runs in (never null)
servletContext
)

Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.

The default implementation is empty.

protected boolean
isContextRequired()

Overrides org.springframework.context.support.ApplicationObjectSupport.isContextRequired.

Overrides the base class behavior to enforce running in an ApplicationContext.

public final void
setServletContext(ServletContext
the ServletContext object to be used by this object
servletContext
)

Implements org.springframework.web.context.ServletContextAware.setServletContext.

Set the ServletContext 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.

Inherited from org.springframework.context.support.ApplicationObjectSupport:
getApplicationContextgetMessageSourceAccessorinitApplicationContextobtainApplicationContextrequiredContextClasssetApplicationContext

Field Detail

servletContextback to summary
private ServletContext servletContext
Annotations
@Nullable

Constructor Detail

WebApplicationObjectSupportback to summary
public WebApplicationObjectSupport()

Method Detail

getServletContextback to summary
protected final ServletContext getServletContext() throws IllegalStateException

Return the current ServletContext.

Annotations
@Nullable
Exceptions
IllegalStateException:
if not running within a required ServletContext
See Also
isContextRequired()
getTempDirback to summary
protected final File getTempDir() throws IllegalStateException

Return the temporary directory for the current web application, as provided by the servlet container.

Returns:File

the File representing the temporary directory

Exceptions
IllegalStateException:
if not running within a ServletContext
See Also
org.springframework.web.util.WebUtils#getTempDir(jakarta.servlet.ServletContext)
getWebApplicationContextback to summary
protected final WebApplicationContext getWebApplicationContext() throws IllegalStateException

Return the current application context as WebApplicationContext.

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.

Annotations
@Nullable
Exceptions
IllegalStateException:
if not running in a WebApplicationContext
See Also
getApplicationContext()
initApplicationContextback to summary
protected void initApplicationContext(ApplicationContext context)

Overrides org.springframework.context.support.ApplicationObjectSupport.initApplicationContext.

Calls initServletContext(jakarta.servlet.ServletContext) if the given ApplicationContext is a WebApplicationContext.

Parameters
context:ApplicationContext

Doc from org.springframework.context.support.ApplicationObjectSupport.initApplicationContext.

the containing ApplicationContext

Annotations
@Override
initServletContextback to summary
protected void initServletContext(ServletContext servletContext)

Subclasses may override this for custom initialization based on the ServletContext that this application object runs in.

The default implementation is empty. Called by initApplicationContext(org.springframework.context.ApplicationContext) as well as setServletContext(jakarta.servlet.ServletContext).

Parameters
servletContext:ServletContext

the ServletContext that this application object runs in (never null)

isContextRequiredback to summary
protected boolean isContextRequired()

Overrides org.springframework.context.support.ApplicationObjectSupport.isContextRequired.

Overrides the base class behavior to enforce running in an ApplicationContext. All accessors will throw IllegalStateException if not running in a context.

Annotations
@Override
See Also
getApplicationContext(), getMessageSourceAccessor(), getWebApplicationContext(), getServletContext(), getTempDir()
setServletContextback to summary
public final void setServletContext(ServletContext servletContext)

Implements org.springframework.web.context.ServletContextAware.setServletContext.

Doc from org.springframework.web.context.ServletContextAware.setServletContext.

Set the ServletContext 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.

Parameters
servletContext:ServletContext

the ServletContext object to be used by this object

Annotations
@Override