在Spring Cloud Data Flow中将应用程序属性列入白名单

时间:2019-01-30 12:18:54

标签: spring-cloud-dataflow

当我为SCDF创建自定义应用程序时,我可以根据reference定义在创建新的流/任务时通过仪表板可见的相关属性。我创建了一个spring-configuration-metadata-whitelist.properties文件,如下所示:

configuration-properties.classes=com.example.MySourceProperties
configuration-properties.names=my.prop1,my.prop2

当我通过仪表板创建新的流定义时,在com.example.MySourceProperties中定义的所有属性都显示在属性对话框中,但没有显示my.prop1my.prop2。这两个属性都不是可选的,必须始终由用户设置。如何在属性对话框中添加它们?

1 个答案:

答案 0 :(得分:0)

这告诉它从Task1属性类中提取这些属性的类 我们可以将其与“ @EnableConfigurationProperties(Task1Properties.class)声明一起使用

configuration-properties.classes = com.shifthunter.tasks。 Task1Properties

Task1Properties.java

package com.shifthunter.tasks;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("pulldata-task")
public class Task1Properties {

    /**
     * The path to get the source doc from
     */
    private String sourceFilePath;

    /**
     * The path to put the destination doc 
     */
    private String destinationFilePath;

    /**
     * Property to drive the exit code
     */
    private String controlMessage;

    public String getSourceFilePath() {
        return sourceFilePath;
    }

    public void setSourceFilePath(String sourceFilePath) {
        this.sourceFilePath = sourceFilePath;
    }

    public String getDestinationFilePath() {
        return destinationFilePath;
    }

    public void setDestinationFilePath(String destinationFilePath) {
        this.destinationFilePath = destinationFilePath;
    }

    public String getControlMessage() {
        return controlMessage;
    }

    public void setControlMessage(String controlMessage) {
        this.controlMessage = controlMessage;
    }
}

ShiftHunterTaskPullDataApp.java

package com.shifthunter.tasks;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableTask
@EnableConfigurationProperties(Task1Properties.class)
@SpringBootApplication
public class ShiftHunterTaskPullDataApp {

    public static void main(String[] args) {
        SpringApplication.run(ShiftHunterTaskPullDataApp.class, args);
    }

    @Bean
    public Task1 task1() {
        return new Task1();
    }

    public class Task1 implements CommandLineRunner {

        @Autowired
        private Task1Properties config;

        @Override
        public void run(String... strings) throws Exception {

            System.out.println("source: " + config.getSourceFilePath());
            System.out.println("destination: " + config.getDestinationFilePath());
            System.out.println("control message: " + config.getControlMessage());

            if(config.getControlMessage().equals("fail")) {
                System.out.println("throwing an exception ...");
                throw new Exception("I'm ANGRY");
            }

            System.out.println("pulldata-task complete!");

        }
    }
}

Sream Dataflow任务提取数据

 app register --name task-pull-data --type task --uri maven://com.shifthunter.tasks:shifthunter-task-pulldata:jar:0.0.1-SNAPSHOT

task-pull-data - Details