0

Trying to write a custom task in Spring Cloud Dataflow which will create a Spring Batch application that implements the Task interface provided by the Spring Cloud Task.

I have try all possible ways to implement this but I am getting this error

The import org.springframework.cloud.task.Task cannot be resolved

I have added the following dependency in my project.

  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 this 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!");
  }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1

The reason it is not working is that org.springframework.cloud.task.Task does not exist.

Maybe you were trying to implement org.springframework.cloud.task.configuration.TaskConfigurer ?

Evandro
  • 137
  • 1
  • 1
  • 13
0

Please update your Spring Boot Version to 2.7.8

Please replace the following in your pom.xml

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-task-core</artifactId>
    <version>2.4.1</version>
</dependency>

with

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-task</artifactId>
</dependency>