public class ServletContextAttributeExporter extends java.lang.Object implements ServletContextAware
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.
javax.servlet.ServletContext#getAttribute
,
WebApplicationContextUtils.getWebApplicationContext(ServletContext)
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.Object> |
attributes |
protected Log |
logger |
Constructor and Description |
---|
ServletContextAttributeExporter() |
Modifier and Type | Method and Description |
---|---|
void |
setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
Set the ServletContext attributes to expose as key-value pairs.
|
void |
setServletContext(ServletContext servletContext)
Set the
ServletContext that this object runs in. |
protected final Log logger
@Nullable private java.util.Map<java.lang.String,java.lang.Object> attributes
public void setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
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.
public void setServletContext(ServletContext servletContext)
ServletContextAware
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
.
setServletContext
in interface ServletContextAware
servletContext
- ServletContext object to be used by this objectInitializingBean.afterPropertiesSet()
,
ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)