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.
jakarta.servlet.ServletContext#getAttribute , WebApplicationContextUtils#getWebApplicationContext
| Modifier and Type | Field and Description |
|---|---|
| private Map | |
| protected final Log |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method 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. Set the Invoked after population of normal bean properties but before an init
callback like InitializingBean's |
| attributes | back to summary |
|---|---|
| private Map<String, Object> attributes
| |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| ServletContextAttributeExporter | back to summary |
|---|---|
| public ServletContextAttributeExporter() | |
| setAttributes | back 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. | |
| setServletContext | back to summary |
|---|---|
| public void setServletContext(ServletContext servletContext) Implements org. Doc from org. Set the Invoked after population of normal bean properties but before an init
callback like InitializingBean's
| |