Reputation: 6877
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?
Upvotes: 3
Views: 4579
Reputation: 10632
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>
Upvotes: 8
Reputation: 3151
/myprops.properties
.Add a property-placeholder to your context-config:
<context:property-placeholder location="myprops.properties"/>
or, if you are using java config:
@Configuration
@PropertySource("classpath:myprops.properties")
public class ApplicationConfiguration {
...
}
Upvotes: 0