Home > Enterprise >  The import org.springframework.cloud.task.Task cannot be resolved
The import org.springframework.cloud.task.Task cannot be resolved

Time:02-04

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 posible way to impliment this but i am getting this error The import org.springframework.cloud.task.Task cannot be resolved I have addedd following dependecny iin 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 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!");
  }

}

CodePudding user response:

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 ?

CodePudding user response:

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>
  • Related