【问题标题】:Spring cloud pass argumentsSpring Cloud 传递参数
【发布时间】:2020-05-10 02:04:22
【问题描述】:

我的应用程序已经配置了 spring cloud config,我想通过 jvm agrument 来运行这个应用程序:

bootsrap.yml 配置

  spring.application.name: app
spring.cloud.config:
  enabled: ${SPRING_CONFIG_ENABLED:false}
  uri: ${SPRING_CONFIG_URI:http://ip:9097/}

我想传递这样的参数但不起作用:

gradle bootRunLocal -DSPRING_CONFIG_ENABLED=true     -DSPRING_CONFIG_URI=http://localhost:9097/

【问题讨论】:

  • 你的文件真的叫bootsrap.yml(而不是bootstrap.yml)吗?第一行真的有这两个空格吗?
  • 文件名为 bootstrap.yml ,问题已解决,谢谢;

标签: java spring-boot gradle spring-cloud-config


【解决方案1】:

尝试在 build.gradle 文件中配置 bootrun 任务如下:

bootRun {
    systemProperties System.properties
}

【讨论】:

    【解决方案2】:

    我通过在 bootRun 中添加此代码来解决问题:

       bootRun {
            if (project.hasProperty('args')) {
                args project.args.split(',')
            }
        }
    

    运行任务:

    gradle bootRun -Pargs=--spring.profiles.active=local,--SPRING_CONFIG_ENABLED=true,--SPRING_CONFIG_URI=http://localhost:9097/
    

    【讨论】:

      猜你喜欢
      • 2020-09-13
      • 2020-07-13
      • 2021-10-03
      • 2018-08-31
      • 2011-07-05
      • 1970-01-01
      • 2019-04-27
      • 2016-04-03
      • 1970-01-01
      相关资源
      最近更新 更多