使用 Spring Cloud Data Flow 注册自定义 Spring Cloud 任务 [英] Registering Custom Spring Cloud Task with Spring Cloud Data Flow

查看:66
本文介绍了使用 Spring Cloud Data Flow 注册自定义 Spring Cloud 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始使用 Spring Cloud Data Flow,并且想要实现一个我想使用它的简单 Spring Cloud 任务.

I'm getting started with Spring Cloud Data Flow and want to implement a simple Spring Cloud Task I want to use with it.

我创建了一个 hello world 示例 来自文档.当我在 IDE 中运行它时,它可以毫无问题地执行并打印hello world".它使用以下 JDBC 连接:

I created a hello world example from the documentation. When I run it in my IDE it executes without any problems and prints 'hello world'. It is using the following JDBC connection:

o.s.j.datasource.SimpleDriverDataSource : 创建到 [jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false] 的新 JDBC 驱动程序连接

o.s.j.datasource.SimpleDriverDataSource : Creating new JDBC Driver Connection to [jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false]

我使用 dockerized Local Spring Data Flow Server,它使用以下 JDBC 连接作为其元数据:

I use the dockerized Local Spring Data Flow Server which uses the following JDBC connection for its metadata:

o.s.c.d.s.config.web.WebConfiguration:使用 URL 启动 H2 服务器:jdbc:h2:tcp://localhost:19092/mem:dataflow

o.s.c.d.s.config.web.WebConfiguration : Starting H2 Server with URL: jdbc:h2:tcp://localhost:19092/mem:dataflow

当我将任务部署到服务器并启动它时,出现以下异常:

When I deploy my task to the server and start it I get the following exception:

org.springframework.context.ApplicationContextException: 无法启动 bean 'taskLifecycleListener';嵌套异常是 java.lang.IllegalArgumentException: Invalid TaskExecution, ID 1 not found

org.springframework.context.ApplicationContextException: Failed to start bean 'taskLifecycleListener'; nested exception is java.lang.IllegalArgumentException: Invalid TaskExecution, ID 1 not found

这是因为Task和服务器使用不同的H2数据库.我以某种方式无法覆盖任务的数据库配置.我在类路径中有 H2 和以下 application.yml 配置以匹配服务器:

This is because the Task and the server use different H2 databases. I somehow cannot override the database configuration of the task. I have H2 in the classpath and the following application.yml configuration to match the server:

spring:
  datasource:
      url: jdbc:h2:tcp://localhost:19092/mem:dataflow
      username: sa
      password:
      driver-class-name: org.h2.Driver

它永远不会被应用.它始终使用预配置的 jdbc:h2:mem:testdb 连接.我怎样才能让它运行?

It never gets applied. It always uses the preconfigured jdbc:h2:mem:testdb-connection. How can I get this to run?

推荐答案

此异常表示该任务未连接到数据流正在使用的数据存储.显然您使用的是 Spring Cloud 的默认数据库数据流.
我邀请你这样做:

This exception indicates that the task did not connect to the datastore that is being used by dataflow.Apparently you're using the default database of Spring Cloud Data Flow.
I invite you to do this:

  • 在任务的 pom.xml 中添加以下依赖项:

  • add the following dependency in the pom.xml of your task:

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

  • 如果之前的提示不起作用.使用spring initailizr 1.5.14版本的Spring boot +上一步

  • if the previous tips din't work. Use the spring initailizr with the 1.5.14 version of Spring boot + the previous step

    如果还是不行,试试覆盖Spring cloud DataFlow的数据库配置 +在你的task的pom.xml中添加相应的依赖

    If it still doesn't work try to override the database configuration of Spring cloud DataFlow + add the corresponding dependency in the pom.xml of your task

    希望能帮到你

    这篇关于使用 Spring Cloud Data Flow 注册自定义 Spring Cloud 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆