尝试在Spring云数据流中编写一个自定义任务,该任务将创建一个Spring批处理应用程序,该应用程序实现Spring云任务提供的任务接口。我已经尝试了所有可能的方法来实现这一点,但我得到了这个错误The import org.springframework.cloud.task.Task cannot be resolved
我在我的项目中添加了以下依赖项。
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>spring-cloud-task-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-cloud-task-example</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-core</artifactId>
<version>2.4.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>```
And java Code
package com.example.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.task.Task;
import org.springframework.cloud.task.configuration.EnableTask;
@EnableTask
@SpringBootApplication
public class SpringCloudTaskExample implements Task {
public static void main(String[] args) {
SpringApplication.run(SpringCloudTaskExample.class, args);
}
@Override
public void run(String... args) throws Exception {
System.out.println("Running Spring Cloud Task Example!");
}
}
1条答案
按热度按时间ttygqcqt1#
它不工作的原因是
org.springframework.cloud.task.Task
不存在。也许您正在尝试实现
org.springframework.cloud.task.configuration.TaskConfigurer
?