【问题标题】:Failed to start bean 'taskLifecycleListener'; nested exception is java.lang.IllegalArgumentException: Invalid TaskExecution, ID 1 not found无法启动 bean 'taskLifecycleListener';嵌套异常是 java.lang.IllegalArgumentException: Invalid TaskExecution, ID 1 not found
【发布时间】:2019-10-26 12:17:36
【问题描述】:

问题:

我正在使用 spring boot 项目并作为 @Enabletask 并尝试使用 spring 数据流运行。

我已经启动了 spring 数据流服务器,在 shell 中我尝试注册应用程序并创建任务,当我运行任务时出现错误。

默认情况下它使用 H2 数据库,但我也尝试使用 mysql,但面临同样的问题。

由于 java.lang.IllegalArgumentException: Invalid TaskExecution, ID 1 not found, application is not able to run and I can see start time, end time and exit code on localhost:9393/

以下是我已经尝试过的解决方案,

1) 使用 mysql 连接参数运行数据流服务器。 --spring.datasource.url=jdbc:mysql://localhost:3306/mydb --spring.datasource.username=root --spring.datasource.driver-class-name=org.mariadb.jdbc.Driver

2) 使用 mysql 连接参数运行数据流 shell。 --spring.datasource.url=jdbc:mysql://localhost:3306/mydb --spring.datasource.username=root --spring.datasource.driver-class-name=org.mariadb.jdbc.Driver

3) 使用mysql连接参数执行任务。 --spring.datasource.url=jdbc:mysql://localhost:3306/mydb --spring.datasource.username=root --spring.datasource.driver-class-name=org.mariadb.jdbc.Driver

已经在 pom 文件中添加了 mysql 依赖。

请看下面的主类代码

主类:

package com.example.demo;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableTask
public class test {
    @Bean
    public CommandLineRunner commandLineRunner() {
        return new HelloWorldCommandLineRunner();
    }

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

    public static class HelloWorldCommandLineRunner implements CommandLineRunner {

        @Override
        public void run(String... strings) throws Exception {
            System.out.println("Hello, World!");
        }
    }
}

Pom


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath />
        <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <!--    <spring-cloud.version>Greenwich.SR1</spring-cloud.version> -->
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-task</artifactId>
            <version>1.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <version>8.0.16</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

【问题讨论】:

    标签: java spring-cloud spring-cloud-config spring-cloud-dataflow


    【解决方案1】:

    我曾在 github 上报告过类似的问题。 https://github.com/spring-cloud/spring-cloud-task/issues/446

    我的问题是 spring boot 和 spring cloud 版本。正如我在您的案例中看到的那样,您使用的是 spring boot 2.0.5 RELEASE,而对于 spring cloud task starter,您使用的是 1.2.3 RELEASE。这可能会导致兼容性问题。

    我建议您尝试该依赖项的更新版本,您可以在此处找到 - https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-task

    <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-task -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-task</artifactId>
        <version>2.0.2.RELEASE</version>
    </dependency>
    

    1.x.x 版本的 spring cloud starter task 兼容 1.x.x 版本的 spring boot,同样 2.x.x 将兼容 2.x.x。

    【讨论】:

      【解决方案2】:

      你需要对 spring-boot-starter-jdbc 的依赖吗?也是mariadb驱动程序。我假设mysql服务器正在运行。检查日志文件以了解早期的错误。

      【讨论】:

      • 另外你不需要shell的连接参数。
      • 我假设 mysql 服务器正在运行 - 是的,你需要依赖 spring-boot-starter-jdbc - 否 还有 mariadb 驱动程序 - 它在 springcloudserver jar 中,在我的 pom 中我添加了 mysqlconnector 依赖项.
      猜你喜欢
      • 1970-01-01
      • 2019-01-02
      • 2022-06-29
      • 2015-12-26
      • 2018-06-09
      • 1970-01-01
      • 1970-01-01
      • 2022-06-26
      • 2019-09-09
      相关资源
      最近更新 更多