在Spring 3.2 MVC配置中设置ServletContext的属性

Mar*_*vic 3 java spring servlets spring-mvc

我遇到了一个非常简单的任务:如何在Spring MVC 3.2配置中设置ServletContext属性?

我发现类似的东西可以用ServletContextPropertyPlaceholderConfigurer来完成,但是从春季3.1这被视为过时:
" 已过时.在Spring 3.1赞成PropertySourcesPlaceholderConfigurer的与StandardServletEnvironment结合. "

这并没有告诉我多少,因为我不知道如何使用StandardServletEnvironment.

有什么建议吗?

Deb*_*kia 8

您可以使用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>
Run Code Online (Sandbox Code Playgroud)