使用 Spring Cloud Data Flow 注册自定义 Spring Cloud 任务

2024-03-22

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

我创建了一个你好世界示例 https://docs.spring.io/spring-cloud-task/docs/2.0.0.RELEASE/reference/htmlsingle/#getting-started-developing-first-task从文档中。当我在 IDE 中运行它时,它执行时没有任何问题并打印“hello world”。它使用以下 JDBC 连接:

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

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

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

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

org.springframework.context.ApplicationContextException:无法启动bean“taskLifecycleListener”;嵌套异常是 java.lang.IllegalArgumentException:无效的 TaskExecution,未找到 ID 1

这是因为任务和服务器使用不同的H2数据库。我不知何故无法覆盖任务的数据库配置。我的类路径中有 H2 以及以下 application.yml 配置来匹配服务器:

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

它永远不会被应用。它总是使用预先配置的jdbc:h2:mem:testdb-联系。我怎样才能让它运行?


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

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

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    
  • 如果前面的提示不起作用。使用 Spring Initializr 配合 1.5.14 版本的 Spring boot + 上一步

  • 如果仍然不起作用,请尝试覆盖Spring cloud DataFlow的数据库配置 http://docs.spring.io/spring-cloud-dataflow/docs/1.5.1.RELEASE/reference/htmlsingle/#configuration-rdbms+ 在任务的 pom.xml 中添加相应的依赖项

我希望它会有所帮助

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Spring Cloud Data Flow 注册自定义 Spring Cloud 任务 的相关文章

随机推荐