Spring 云数据流的自定义任务中缺少参数

Missing parameters in custom Task for Spring Cloud Data Flow

我正在开发一个使用 Spring Cloud Data Flow 的任务,但我看不到我的任务(它是一个 Spring 启动应用程序)的执行参数或如何执行任务。

我正在导入我的应用程序作为基础,并将项目作为基础:spring-cloud-starter-task-timestamp

这是我的 pom,我使用 Spring Initializr 制作了它,然后使用 timestamp-task 应用程序进行了调整。

<groupId>teste</groupId>
<artifactId>scdf-neo4j-task</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>scdf-neo4j-task</name>
<description>scdf-neo4j-task</description>

<parent>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-task-parent</artifactId>
    <version>2.3.0-SNAPSHOT</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <spring-cloud.version>Hoxton.SR5</spring-cloud.version>
    <start-class>teste.scdf.Neo4jTaskApplication</start-class>
    <skipInstall>true</skipInstall>
</properties>

<dependencies>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-task</artifactId>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

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

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>

    <dependency>
        <groupId>org.neo4j.driver</groupId>
        <artifactId>neo4j-java-driver</artifactId>
        <version>4.0.1</version>
    </dependency>

</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-task-dependencies</artifactId>
            <version>2.3.0-SNAPSHOT</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/libs-snapshot-local</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone-local</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-releases</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/release</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-libs-release</id>
        <name>Spring Libs Release</name>
        <url>https://repo.spring.io/libs-release</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <id>spring-milestone-release</id>
        <name>Spring Milestone Release</name>
        <url>https://repo.spring.io/libs-milestone</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-releases></id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/libs-snapshot-local</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone-local</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>
</project>

这是我实现 CommandLineRunner 的主要 Spring 启动 class:

@Log
@EnableTask
@SpringBootApplication
@EnableConfigurationProperties({Neo4jTaskProperties.class})
public class Neo4jTaskApplication
{

    @Autowired
    public Neo4jTaskProperties neo4jTaskProperties;

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

    @Bean
    public CommandLineRunner commandLineRunner()
    {
        return args ->
        {
            Driver driver = GraphDatabase.driver(
                    neo4jTaskProperties.getUri(),
                    AuthTokens.basic(
                            neo4jTaskProperties.getUsername(),
                            neo4jTaskProperties.getPassword()
                    )
            );

            try (Session session = driver.session())
            {
                session.writeTransaction(transactionWork ->
                {
                    ResultSummary resultSummary = transactionWork.run(neo4jTaskProperties.getCommand()).consume();

                    return resultSummary;
                });
            }
        };
    }
}

这是我的属性 class:

@Data
@ConfigurationProperties("neo4j")
public class Neo4jTaskProperties {

    private String uri;

    private String username;

    private String password;

    private String command;

}

我该如何解决这个问题?

您需要将任务应用程序属性添加到 metadata Cloud Data Flow 知道如何提取和提供它们的应用程序 metadata 中。

您可以参考这个 page,它会引导您完成如何添加元数据。

此外,您可以查看此 sample 配置作为如何添加此类元数据的参考。