【问题标题】:Environment specific configuration property files in servlet applicationservlet 应用程序中特定于环境的配置属性文件
【发布时间】:2020-10-16 09:03:07
【问题描述】:

我想以这样的方式在 servlet 应用程序中实现代码,该方式将具有环境特定的属性文件,如 spring boot application-dev.properties、application-stage.properties 等。

因此,根据配置的环境名称,在运行应用程序时需要参考相应的属性文件。

但我没有办法这样做。所以大家可以建议我如何实现它。

【问题讨论】:

    标签: java servlet-3.0


    【解决方案1】:

    一个解决方案应该是传递一个 JVM 参数并在 Servlet Filter 中读取此参数,例如以完成您想要的。 JVM 参数可以称为:例如“configurationFile”。

    1. 传递一个 JVM 参数:-DConfigurationFile=value
    2. 在您的代码中读取它:value=System.getProperty("ConfigurationFile");
    3. 做你想做的处理

    最好的问候,

    【讨论】:

      猜你喜欢
      • 2017-10-29
      • 2011-09-11
      • 2013-05-16
      • 2016-02-17
      • 1970-01-01
      • 2020-08-16
      • 1970-01-01
      • 2017-05-20
      • 2011-06-28
      相关资源
      最近更新 更多