Java 在Spring3.2MVC配置中设置ServletContext的属性

Java 在Spring3.2MVC配置中设置ServletContext的属性,java,spring,servlets,spring-mvc,Java,Spring,Servlets,Spring Mvc,我陷入了一个非常简单的任务:如何在SpringMVC3.2配置中设置ServletContext属性 我发现ServletContextPropertyPlaceHolderConfigure也可以做类似的事情,但从Spring3.1开始,这被认为是不推荐的: “已弃用。在Spring 3.1中,支持PropertySourcesPlaceholderConfigurer与StandardServleteEnvironment结合使用。” 这并没有告诉我太多,因为我不知道如何使用Standard

我陷入了一个非常简单的任务:如何在SpringMVC3.2配置中设置ServletContext属性

我发现ServletContextPropertyPlaceHolderConfigure也可以做类似的事情,但从Spring3.1开始,这被认为是不推荐的:
已弃用。在Spring 3.1中,支持PropertySourcesPlaceholderConfigurer与StandardServleteEnvironment结合使用。”

这并没有告诉我太多,因为我不知道如何使用StandardServleteEnvironment实现这一点

有什么建议吗

  • 在类路径中的某个位置创建*.properties文件,例如
    /myprops.properties
  • 将属性占位符添加到上下文配置:

  • 或者,如果您使用的是java配置:

    @Configuration
    @PropertySource("classpath:myprops.properties")
    public class ApplicationConfiguration {
        ...
    }
    
    你可以用这个。在配置文件中定义如下所示的
    ServletContextAttributeExporter
    bean,并将其
    attributes
    属性设置为要放入
    ServletContext
    键和值对的映射:

    
    
    正是我需要的!谢谢,请提供代码,这是如何用纯java配置完成的?那么如何在jsp中获取属性呢?当您指的是“context config”时,
    application context.xml
    对吗?谢谢。一旦我将
    放入
    应用程序上下文.xml
    中,再加上
    @PropertySource(“classpath:myprops.properties”)
    ,我可以执行
    @Value()
    来获取文件I/O的
    myprops.properties
    的内容吗?@user75782131不是“plus”,请使用