【问题标题】:Loading spring application-*.properties加载弹簧应用程序-*.properties
【发布时间】:2018-03-09 07:29:06
【问题描述】:

我想知道是否有一种方法可以在 spring 应用程序中动态引用多个 application-*.properties 文件中的键。我面临的挑战是每个应用程序的属性文件名可能不同。我尝试了 spring.config.location、spring.config.name 的各种组合,使用了 ClassPathResource 但没有运气

例如在 src/main/resources 中,我可能拥有应用程序 A application.properties、application-system-X.properties、application-system-Y.properties

例如在 src/main/resources 我可能有应用程序 B、application.properties、application-system-P.properties、application-system-Q.properties

【问题讨论】:

    标签: spring


    【解决方案1】:

    我不确定我是否正确理解了您的问题。但在 Spring Boot 中,您可以通过配置文件动态使用不同的 application-*.properties

    这些 profile-specific application properties 可以存在于您打包的 jar 的内部和外部(application-{profile}.properties 和 YAML 变体)。

    我也可以推荐阅读documentation on externalising your configuration with Spring Boot

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      • 2022-07-21
      • 1970-01-01
      相关资源
      最近更新 更多