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

问题描述 投票:0回答:1

当我为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却没有。这两个属性都不是可选的,必须始终由用户设置。如何将它们包括在属性对话框中?

spring-cloud-dataflow
1个回答
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数据流任务-拉数据

 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

© www.soinside.com 2019 - 2024. All rights reserved.