Registering Custom Spring Cloud Task with Spring Cloud Data Flow

痞子三分冷 提交于 2021-02-08 05:02:31

问题


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

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 : Creating new JDBC Driver Connection to [jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false]

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 : 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: Failed to start bean 'taskLifecycleListener'; nested exception is java.lang.IllegalArgumentException: Invalid TaskExecution, ID 1 not found

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

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


回答1:


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:

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

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    
  • if the previous tips din't work. Use the spring initailizr with the 1.5.14 version of Spring boot + the previous step

  • 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

I hope it will help



来源:https://stackoverflow.com/questions/50913787/registering-custom-spring-cloud-task-with-spring-cloud-data-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!