【问题标题】:How to get properties from gradle.properties into application.yaml如何从 gradle.properties 获取属性到 application.yaml
【发布时间】:2016-10-21 09:14:56
【问题描述】:

我有 gradle 的多项目结构,并使用gradle.properties 文件来存储环境变量。 我还在一些项目中使用带有application.properties 文件的SpringBoot 应用程序环境。
在gradle.properties 文件中我有api.port=8080,要在application.properties 文件中获取它,我使用@api.port@ 值,即@..@ 占位符,就像在官方文档中一样。
如果我将 application.properties 重命名为 application.yaml,我应该使用哪些占位符?
我尝试使用:
server: port: @api.port@
server: port: '@api.port@'
server: port: ${api.port}
如果我将gradle.properties 重命名为gradle.yaml,则会在build.gradle 处读取属性时发生错误

【问题讨论】:

    标签: java gradle spring-boot yaml


    【解决方案1】:

    答案很简单,之前我用这个带属性文件,现在简单阅读自己的代码更多载体:

    processResources {
            filesMatching('application.yaml') {
                filter ReplaceTokens, tokens: [
                        'api.port'         : project.property('api.port')
                ]
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2014-12-07
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多