首页 > 解决方案 > Spring Cloud 数据流自定义应用属性

问题描述

我创建了一个自定义的 Spring Cloud 数据流应用程序。我想用它创建一个流并将一些应用程序属性放入其中,因为我们可以为提供的应用程序日志(0/3 属性)添加: 在此处输入图像描述

我尝试使用application.yml文件resources folder

spring:
  application:
    toto: 'titi'

但它没有用。

我也尝试创建一些Properties.class

public class Properties {

    //public static final String PREFIX = "portin";
    private String toto;

    public Properties(String toto) {
        this.toto = toto;
    }

    public Properties() {
    }

    public String getToto() {
        return toto;
    }

    public void setToto(String toto) {
        this.toto = toto;
    }
}

并在文件中添加以下声明dataflow-configuration-metadata-whitelist.properties

configuration-properties.classes=com.mycompany.Properties 但这并不成功,并且该应用程序没有任何属性。

我在文档中找不到任何相关的东西(我不是说英语的母语,所以我可能误读了一些东西)。

感谢您的帮助

在 META-INF 文件夹中移动 dataflow-configuration-metadata-whitelist.properties 后编辑

白名单属性文件不在 META-INF 文件夹下。现在我有这个项目:

在此处输入图像描述

但这无济于事。pom.xml 是:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-app-starter-metadata-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>aggregate-metadata</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>aggregate-metadata</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

然后我用 docker 构建应用程序。那么码头工人有什么具体要做的吗?我可以阅读文档,但看不到我的项目中缺少什么

标签: spring-cloud-dataflowspring-cloud-dataflow-ui

解决方案


对于自定义应用程序属性,您可以确保您是否正确遵循 Spring Boot 配置属性配置。您可以在此处查看开箱即用应用程序中的一些示例

我不确定您使用哪个版本的 SCDF。如果您使用的是 SCDF 2.x 之前的版本,则白名单属性的名称需要为spring-configuration-metadata-whitelist.properties具有该名称的白名单属性文件,dataflow-configuration-metadata-whitelist.properties仅从 SCDF 2.x 开始支持。

此外,请确保将白名单属性文件放入/META-INF 类路径(src/main/resources 目录)下的目录中,例如此处

关于文档,请按照SCDF 文档中提到的说明进行操作。


推荐阅读