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

public Class ServletContextAttributeExporter

extends Object
implements ServletContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.web.context.ServletContextAware, org.springframework.beans.factory.Aware
Imports
java.util.Map, jakarta.servlet.ServletContext, org.apache.commons.logging.Log, .LogFactory, org.springframework.lang.Nullable, org.springframework.web.context.ServletContextAware

Exporter that takes Spring-defined objects and exposes them as ServletContext attributes. Usually, bean references will be used to export Spring-defined beans as ServletContext attributes.

Useful to make Spring-defined beans available to code that is not aware of Spring at all, but rather just of the Servlet API. Client code can then use plain ServletContext attribute lookups to access those objects, despite them being defined in a Spring application context.

Alternatively, consider using the WebApplicationContextUtils class to access Spring-defined beans via the WebApplicationContext interface. This makes client code aware of Spring API, of course.

Author
Juergen Hoeller
Since
1.1.4
See Also
jakarta.servlet.ServletContext#getAttribute, WebApplicationContextUtils#getWebApplicationContext

Field Summary

Modifier and TypeField and Description
private Map<String, Object>
protected final Log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
setAttributes(Map<String, Object> attributes)

Set the ServletContext attributes to expose as key-value pairs.

public 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 java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributesback to summary
private Map<String, Object> attributes
Annotations
@Nullable
loggerback to summary
protected final Log logger

Constructor Detail

ServletContextAttributeExporterback to summary
public ServletContextAttributeExporter()

Method Detail

setAttributesback to summary
public void setAttributes(Map<String, Object> attributes)

Set the ServletContext attributes to expose as key-value pairs. Each key will be considered a ServletContext attributes key, and each value will be used as corresponding attribute value.

Usually, you will use bean references for the values, to export Spring-defined beans as ServletContext attributes. Of course, it is also possible to define plain values to export.

setServletContextback to summary
public 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