【问题标题】:Profile specific application.properties file in Spring boot and default injection of values for multiple profilesSpring boot 中配置文件特定的 application.properties 文件和多个配置文件的默认值注入
【发布时间】:2021-05-15 05:28:22
【问题描述】:

application.properties:

app.profile=${spring.profiles.active} spring.profiles.active=dev

service.endpoint=${${spring.profiles.active}.service.endpoint} service.api.user=${${spring.profiles.active}.service.api.user}

开发

dev.service.endpoint = https://test.google.com/
dev.service.api.user = /api/v1/user

产品

prod.service.endpoint = https://google.com/
prod.service.api.user = /api/v1/user

有没有办法通过删除两个环境中的 common which 在这种情况下为 service.api.user 的值来进一步优化 以便其余值转到默认配置文件。

【问题讨论】:

    标签: java spring spring-boot configuration


    【解决方案1】:

    这个建议怎么样? 如果你有 dev 和 prod 的属性,stg 和 dev 和 prod 很常见,但 stg 不常见

    application.properties

    service.api.user = /api/v1/user
    

    application-dev.properties、application-prod.properties

    #service.api.user = /api/v1/user
    

    应用程序-stg.properties

    service.api.user = /api/v1/stg
    

    如果配置文件是 dev,application-dev.properties 没有 'service.api.user' spring find 'service.api.user' of application.properties

    【讨论】:

      猜你喜欢
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      • 2020-09-20
      • 2020-05-07
      • 2021-04-18
      • 1970-01-01
      相关资源
      最近更新 更多