我正在使用spring boot项目,并将其设置为@Enabletask,并尝试使用spring数据流运行。
我启动了spring数据流服务器,并在shell中尝试注册应用程序并创建任务,当我运行任务时出现错误。
默认情况下,它使用H2数据库,但我也尝试使用mysql,但面临相同的问题。
由于java.lang.IllegalArgumentException:无效的TaskExecution,未找到ID 1,应用程序无法运行,并且我无法在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连接参数运行dataflow 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!");
}
}
}
<?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>
答案 0 :(得分:0)
您需要依赖spring-boot-starter-jdbc吗?也是mariadb驱动程序。我假设mysql服务器正在运行。检查日志文件中是否有较早的错误。
答案 1 :(得分:0)
我在github上曾报道过类似的问题。 https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-task
在我的案例中,问题是Spring Boot和Spring Cloud版本。正如我在您的案例中看到的那样,您正在使用Spring Boot 2.0.5 RELEASE,而对于Spring Cloud Task Starter,您正在使用1.2.3 RELEASE。这可能会导致兼容性问题。
我建议您尝试该依赖关系的较新版本,您可以在此处找到- {{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兼容。