【问题标题】:How to add profile specific properties files when I have custom name to my property file当我的属性文件有自定义名称时如何添加配置文件特定的属性文件
【发布时间】:2017-08-28 00:02:12
【问题描述】:

我的项目的 src/main/resources 文件夹中有名称为 transactionexpiry.properties 的属性文件。

我可以使用 @PropertySource("classpath:/transactionexpiry.properties") 读取代码中的属性

现在我不想添加应用程序范围并将特定于环境的配置文件添加为 transactionexpiry-dev.properties、transactionexpiry-local.properties

但同样适用于 application.properties、application-dev.properties、application-local.properties

有没有办法让它与我之前的设置一起使用?

【问题讨论】:

    标签: spring spring-boot


    【解决方案1】:

    如果您使用的是弹簧型材:

    -Dspring.profiles.active=dev
    

    然后你可以像这样调用属性文件:

    @PropertySource("classpath:/transactionexpiry${spring.profiles.active}.properties")
    

    【讨论】:

      猜你喜欢
      • 2016-01-27
      • 2016-06-11
      • 2020-01-24
      • 2019-06-28
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多