Set attributes of ServletContext in Spring 3.2 MVC configuration
java, servlets, spring, spring-mvc
Solution
You can use ServletContextAttributeExporter for this. Define a `ServletContextAttributeExporter` bean as below in your configuration file and set its `attributes` property to a map of `key and value` pairs that you want to put into `ServletContext`:
<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="myKey" value="1" />
</map>
</property>
</bean>
Problem
I'm stuck on a pretty simple task: how to set ServletContext attributes in Spring MVC 3.2 configuration? I found that something similar can be done with ServletContextPropertyPlaceholderConfigurer, but from Spring 3.1 this is considered as deprecated: "Deprecated. in Spring 3.1 in favor of PropertySourcesPlaceholderConfigurer in conjunction with StandardServletEnvironment." This doesn't tell me much, since I don't know how to do it with StandardServletEnvironment. Any suggestion?