Spring Cloud Data Flow 的自定义任务中缺少参数
Posted
技术标签:
【中文标题】Spring Cloud Data Flow 的自定义任务中缺少参数【英文标题】:Missing parameters in custom Task for Spring Cloud Data Flow 【发布时间】:2020-10-15 00:02:07 【问题描述】:我正在开发一个使用 Spring Cloud Data Flow 的任务,但是我看不到我的任务(这是一个 Spring Boot 应用程序)的执行参数或如何执行该任务。
我将我的应用程序作为基础导入,并将项目作为基础导入:spring-cloud-starter-task-timestamp
这是我的 pom,我使用 Spring Initializr 制作,然后使用时间戳任务应用程序进行调整。
<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 Boot 类:
@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;
);
;
这是我的属性类:
@Data
@ConfigurationProperties("neo4j")
public class Neo4jTaskProperties
private String uri;
private String username;
private String password;
private String command;
我该如何解决这个问题?
【问题讨论】:
【参考方案1】:您需要将您的任务应用程序属性添加到 Spring Cloud Data Flow 知道如何提取并使其可用的应用程序 metadata
。
您可以参考这个page,它会引导您了解如何添加元数据。
此外,您可以查看此sample 配置作为如何添加此类元数据的参考。
【讨论】:
以上是关于Spring Cloud Data Flow 的自定义任务中缺少参数的主要内容,如果未能解决你的问题,请参考以下文章
Swarm 的 Spring Cloud Data Flow 支持
Spring Cloud Data Flow 安全配置和与 RedHat SSO 的集成