问题:
我正在使用spring boot项目和make as @Enabletask,并尝试使用spring数据流运行。
我启动了spring数据流服务器,在shell中,我尝试注册应用程序并创建任务,当我运行任务时,我得到了这个错误。
默认情况下,它使用H2数据库,但我也尝试了mysql,但遇到了同样的问题。
由于java.lang.IllegalArgumentException:无效的TaskExecution,找不到ID %1,应用程序无法运行,并且我无法查看本地主机上的开始时间、结束时间和退出代码:9393/
下面是我已经尝试过的解决方案,
1)使用mysql连接参数运行数据流服务器。--spring.datasource.url=jdbc:mysql://localhost:3306/mydb --spring.datasource.username=根--spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
2)运行带mysql连接参数的数据流shell。--spring.datasource.url=jdbc:mysql://localhost:3306/mydb --spring.datasource.username=根--spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
3)使用mysql连接参数执行任务。--spring.datasource.url=jdbc:mysql://localhost:3306/mydb --spring.datasource.username=根--spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
已经在pom文件中添加了mysql依赖。
下面是main类的代码
主类:
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>发布于 2019-06-12 19:52:04
你需要对spring-boot-starter-jdbc的依赖吗?还有mariadb驱动程序。我假设mysql服务器正在运行。检查日志文件中的早期错误。
发布于 2020-02-13 18:19:14
我在github上报告过类似的问题。https://github.com/spring-cloud/spring-cloud-task/issues/446
正如我在您的案例中所看到的,您使用的是spring boot 2.0.5版本,而对于spring cloud任务启动器,您使用的是1.2.3版本。这可能会导致兼容性问题。
<!-- 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>spring cloud starter任务的1.x.x版本与spring boot的1.x.x版本兼容,同样,2.x.x将与2.x.x兼容。
https://stackoverflow.com/questions/56554480
复制相似问题