我被困在一个非常简单的任务上:如何在 Spring MVC 3.2 配置中设置 ServletContext 属性?
我发现可以使用 ServletContextPropertyPlaceholderConfigurer 完成类似的事情,但是从 Spring 3.1 开始,这被认为已弃用:
“已弃用。在 Spring 3.1 中支持 PropertySourcesPlaceholderConfigurer 与 StandardServletEnvironment 结合使用。”
这并不能告诉我太多信息,因为我不知道如何使用 StandardServletEnvironment 来做到这一点。
有什么建议吗?
最佳答案
您可以使用 ServletContextAttributeExporter为了这。在您的配置文件中定义一个 ServletContextAttributeExporter
bean,并将其 attributes
属性设置为您要放入的 key and value
对的映射ServletContext
:
<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="myKey" value="1" />
</map>
</property>
</bean>
关于java - 在 Spring 3.2 MVC 配置中设置 ServletContext 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20148259/