一尘不染

使用spring-boot:1.5.1和spring-cloud-stream时无法启动bean'inputBindingLifecycle'

spring-boot

我在使用spring-boot:1.5.1时遇到以下错误,但在使用spring-boot:1.4.4时却没有

有人遇到过这个吗?

package org.test;

import lombok.Data;
import lombok.ToString;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;

@SpringBootApplication
@EnableBinding(Sink.class)
public class EtestSmsConsumerApplication {

    @StreamListener(Sink.INPUT)
    public void readSms(SmsRequest smsRequest) {
        System.out.println("Received sms " + smsRequest);
    }

    public static void main(String[] args) {
        SpringApplication.run(EtestSmsConsumerApplication.class, args);
    }
}

@Data
@ToString
class SmsRequest {
    private String message;
}

应用程序属性:

spring.cloud.stream.bindings.input.destination=sms
spring.cloud.stream.bindings.input.content-type=application/json
spring.cloud.stream.bindings.input.group=smsGroup2
server.port=8083

POM.xml

<?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>

    <groupId>com.example</groupId>
    <artifactId>etest-sms-consumer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>etest-sms-consumer</name>
    <description></description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.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>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-stream-kafka</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </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>Dalston.M1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

</project>

抛出异常

org.springframework.context.ApplicationContextException:无法启动bean’inputBindingLifecycle’;
嵌套的异常是java.lang.NoSuchMethodError
:org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter。(Ljava
/ lang / reflect / Method;)V at
org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)〜[spring-
context-4.3
.6.RELEASE.jar:4.3.6.RELEASE]在org.springframework.context.support.DefaultLifecycleProcessor.access
$ 200(DefaultLifecycleProcessor.java:51)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6
.RELEASE]位于org.springframework.context.support.DefaultLifecycleProcessor $
LifecycleGroup.start(DefaultLifecycleProcessor.java:346)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6.RELEASE]位于org.springframework.context
.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6.RELEASE]位于org.springframework.context.support.DefaultLifecycleProcessor。onRefresh(DefaultLifecycleProcessor.java:112)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6.RELEASE]在org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:879)〜[spring
-context-4.3.6.RELEASE.jar:4.3.6.RELEASE],位于org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)〜[spring-
boot-1.5.1.RELEASE。
jar:1.5.1.RELEASE],位于org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6.RELEASE]。
springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)〜[spring-
boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]在org.springframework.boot.SpringApplication处。在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)的refresh(SpringApplication.java:737)[spring-
boot-1.5.1.RELEASE.jar:1.5.1.RELEASE] [spring-boot-1.5
org.springframework.boot.SpringApplication.run(SpringApplication.java:314)上的.1.RELEASE.jar:1.5.1.RELEASE],位于org.springframework.boot.SpringApplication.run(SpringApplication.java:314)[spring-
boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)[spring-
boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:
1151)[spring-
boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]在org.test.EtestSmsConsumerApplication.main(EtestSmsConsumerApplication.java:21)[classes
/:na]在sun.reflect.NativeMethodAccessorImpl.invoke0
(本地方法)〜[na:1.8.0_121],位于sun.reflect.NativeMethodAccessorImpl。在sun.reflect.DelegatingMethodAccessorImpl.invoke处调用(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_121](在java.lang.reflect.Method.invoke(处DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_121]
Method.java:498)〜[na:1.8.0_121] at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)[idea_rt.jar:na]原因:java.lang.NoSuchMethodError
:org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter。(Ljava
/ lang / reflect / Method;)V at
org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter
$
IntegrationMessageListener。(KafkaMessageDrivenChannelAdapter.java:191)〜[spring-
在org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter。(KafkaMessageDrivenChannelAdapter.java:51)处的Integration-
kafka-2.0.1.RELEASE.jar:na] at
org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder.createConsumerEndpoint(KafkaMessageChannelBinder.java:338)〜[spring-
cloud-stream-binder-kafka-1.2.0.M1.jar:1.2.0.M1
]在org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder.createConsumerEndpoint(KafkaMessageChannelBinder.java:93)〜[spring-
cloud-stream-binder-
kafka-1.2.0.M1.jar:1.2.0.M1]在org.springframework.cloud.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:202)〜[spring-
cloud-stream-1.2.0.M1.jar:1.2.0.M1]中。
stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:55)〜[spring-
cloud-stream-1.2.0.M1.jar:1.2.0.M1] at
org.springframework.cloud.stream.binder.AbstractBinder.bindConsumer
(AbstractBinder.java:143)〜[spring-cloud-stream-1.2.0.M1.jar:1.2.0.M1] at
org.springframework.cloud.stream.binding.BindingService.bindConsumer(BindingService.java:98)〜[spring-
cloud
-stream-1.2.0.M1.jar:1.2.0.M1],位于org.springframework.cloud.stream.binding.BindableProxyFactory.bindInputs(BindableProxyFactory.java:208)〜[spring-
cloud-stream-1.2.0。
M1.jar:1.2.0.M1],位于org.springframework.cloud.stream.binding.InputBindingLifecycle.start(InputBindingLifecycle.java:55)〜[spring-
cloud-stream-1.2.0.M1.jar:1.2.0 [M1] at
org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
…省略了19个常见框架jar:1.2.0.M1]位于org.springframework.cloud.stream.binding.BindableProxyFactory.bindInputs(BindableProxyFactory.java:208)〜[spring-
cloud-stream-1.2.0.M1.jar:1.2.0.M1
]在org.springframework.cloud.stream.binding.InputBindingLifecycle.start(InputBindingLifecycle.java:55)〜[spring-
cloud-stream-1.2.0.M1.jar:1.2.0.M1]在org.springframework.context
.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
…省略了19个常见框架jar:1.2.0.M1]位于org.springframework.cloud.stream.binding.BindableProxyFactory.bindInputs(BindableProxyFactory.java:208)〜[spring-
cloud-stream-1.2.0.M1.jar:1.2.0.M1
]在org.springframework.cloud.stream.binding.InputBindingLifecycle.start(InputBindingLifecycle.java:55)〜[spring-
cloud-stream-1.2.0.M1.jar:1.2.0.M1]在org.springframework.context
.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
…省略了19个常见框架springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
…省略了19个常见框架springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)〜[spring-
context-4.3.6.RELEASE.jar:4.3.6.RELEASE] …省略了19个常见框架


阅读 267

收藏
2020-05-30

共1个答案

一尘不染

Chelsea.M1活页夹的发行版和Spring Initializr 之间是不一致的-
Kafka活页夹启动程序要求将0.9依赖项集设置为基准,但是Spring Boot父级将Spring Kafka依赖项覆盖为1.1.2。由于Spring
Integration Kafka不是由Spring Boot管理的,因此由绑定器引入的版本2.0.1与Spring Kafka 1.1.2不兼容。

在这里跟踪:https : //github.com/spring-cloud/spring-cloud-stream-binder-
kafka/issues/88

更新:如果Spring Boot 1.5.2.BUILD-SNAPSHOT在Initializr中使用version
和更高版本,则应检索正确的依赖项集。请注意,需要Kafka0.10.1.x。

2020-05-30