构造函数TaskLaunchRequest(String,List <string>,null,null)未定义-Spring Cloud Task

时间:2018-09-01 18:30:47

标签: spring spring-boot spring-cloud-stream spring-cloud-task

我正在为带有Spring Boot的Spring Cloud 开发代码。在此示例中,我在Spring Cloud Tasks中工作。我使用的是Spring Boot <version>1.4.1.RELEASE</version>,下面的代码运行良好。当我更新<version>2.0.4.RELEASE</version>时,我遇到了错误。

  

构造函数TaskLaunchRequest(String,List,null,null)未定义

TaskProcessor.java

@Component
@EnableBinding(Source.class)
public class TaskProcessor {

    @Autowired
    private Source source;

    public void publishRequest(String payload) {

        //maven://[groupid]:[artifactid]:jar:[version]
        //String url = "maven://pluralsight.demo:pluralsight-springcloud-m3-task:jar:0.0.1-SNAPSHOT";
        String url = "maven://pluralsight.demo:springcloud-m3-tasksink:jar:1.0";

        List<String> input = new ArrayList<String>(Arrays.asList(payload.split(",")));

        TaskLaunchRequest request = new TaskLaunchRequest(url, input, null, null);

        System.out.println("created task launch request ...");

        GenericMessage<TaskLaunchRequest> message = new GenericMessage<>(request);
        this.source.output().send(message);
    }
} 

pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.SR1</spring-cloud.version>
        <spring-cloud-task.version>2.0.0.RELEASE</spring-cloud-task.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-task</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-task-dependencies</artifactId>
                <version>${spring-cloud-task.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

错误图片:

enter image description here

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并且在pom文件中进行了以下修改后,它仍然有效。

  1. 替换您的:

    <spring-cloud.version>Finchley.SR1</spring-cloud.version> 
    

    具有:

    <spring-cloud.version>Brixton.SR6</spring-cloud.version>
    
  2. 替换您的:

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

    具有:

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