首页 > 解决方案 > 如何在组合任务中设置我的应用程序属性?

问题描述

我有一个具有以下定义的组合任务:

task create my-task --definition "taskA && taskB"

当我启动任务并传递一个包含空格的值时,我想为taskA设置一个应用程序属性。同样,我需要为每个子任务设置 Spring 活动配置文件。

TaskA中应用程序属性的 Java 代码如下:

@ConfigurationProperties(prefix = "taskA")
public class TaskAProperties {
  private String name;
  ... setter and getter
}

我尝试了许多命令,但无法使用空格。

task launch my-task --arguments "--composed-task-arguments=--spring.profiles.active=local --composed-task-properties=app.taskA.name='Bill Gates'"

当我打印出name属性时,它为空;

标签: spring-cloud-dataflow

解决方案


在上面的示例中,我将使用属性而不是命令行参数。使用外壳,它看起来像: task launch my-task --properties "app.my-task.taskA.spring.profiles.active=local,app.my-task.taskA.taska.name=Bill Gates". 更多信息可以在这里阅读。

我在您的示例中看到的一个问题是使用@ConfigurationProperties(prefix = "taskA"). 使用 taskA 作为前缀是不正确的,你应该在你的应用程序中得到一个错误,说明类似 Modify 'taskA' so that it conforms to the canonical names requirements.


推荐阅读