文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

SpringBoot整合kafka遇到的版本不对应问题及解决

2024-04-02 19:55

关注

SpringBoot整合kafka遇到版本不对应

SpringBoot 整合 kafka 需要在SpringBoot项目里增加kafka的jar,而最为关键的一点是版本要对应好。

如果你的SpringBoot是2.0.3版本

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

那么你可以用2.1.7版本的kafka

        <!-- kafka -->
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
            <version>2.1.7.RELEASE</version>
        </dependency>

如果你的SpringBoot比较新,用的2.1.0版本

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

那么对应的,你的kafka也应该用新版本

        <!-- https://mvnrepository.com/artifact/org.springframework.kafka/spring-kafka -->
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
            <version>2.2.0.RELEASE</version>
        </dependency>

当然,版本号可能其他方式也可以。

不过如果你用2.1.0版本的SpringBoot,却仍使用2.1.7版本的kafka,则会遇到如下错误:

D:\DevelopFiles\Java\jdk1.8.0_131\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8247 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.4\lib\idea_rt.jar=8248:C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.4\bin" -Dfile.encoding=UTF-8 -classpath D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\charsets.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\deploy.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\access-bridge-64.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\localedata.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\javaws.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\jce.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\jfr.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\jfxswt.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\jsse.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\management-agent.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\plugin.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\resources.jar;D:\DevelopFiles\Java\jdk1.8.0_131\jre\lib\rt.jar;D:\workspace\IDEA\chinaunicom\alarm-query-kafka\target\classes;D:\DevelopFiles\Maven\m2\org\springframework\boot\spring-boot-starter\2.1.0.RELEASE\spring-boot-starter-2.1.0.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\boot\spring-boot\2.1.0.RELEASE\spring-boot-2.1.0.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\boot\spring-boot-autoconfigure\2.1.0.RELEASE\spring-boot-autoconfigure-2.1.0.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\boot\spring-boot-starter-logging\2.1.0.RELEASE\spring-boot-starter-logging-2.1.0.RELEASE.jar;D:\DevelopFiles\Maven\m2\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\DevelopFiles\Maven\m2\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\DevelopFiles\Maven\m2\org\apache\logging\log4j\log4j-to-slf4j\2.11.1\log4j-to-slf4j-2.11.1.jar;D:\DevelopFiles\Maven\m2\org\apache\logging\log4j\log4j-api\2.11.1\log4j-api-2.11.1.jar;D:\DevelopFiles\Maven\m2\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;D:\DevelopFiles\Maven\m2\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\DevelopFiles\Maven\m2\org\springframework\spring-core\5.1.2.RELEASE\spring-core-5.1.2.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\spring-jcl\5.1.2.RELEASE\spring-jcl-5.1.2.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;D:\DevelopFiles\Maven\m2\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\DevelopFiles\Maven\m2\org\springframework\kafka\spring-kafka\2.1.7.RELEASE\spring-kafka-2.1.7.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\spring-context\5.1.2.RELEASE\spring-context-5.1.2.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\spring-aop\5.1.2.RELEASE\spring-aop-5.1.2.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\spring-beans\5.1.2.RELEASE\spring-beans-5.1.2.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\spring-expression\5.1.2.RELEASE\spring-expression-5.1.2.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\spring-messaging\5.1.2.RELEASE\spring-messaging-5.1.2.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\spring-tx\5.1.2.RELEASE\spring-tx-5.1.2.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\springframework\retry\spring-retry\1.2.2.RELEASE\spring-retry-1.2.2.RELEASE.jar;D:\DevelopFiles\Maven\m2\org\apache\kafka\kafka-clients\2.0.0\kafka-clients-2.0.0.jar;D:\DevelopFiles\Maven\m2\org\lz4\lz4-java\1.4.1\lz4-java-1.4.1.jar;D:\DevelopFiles\Maven\m2\org\xerial\snappy\snappy-java\1.1.7.1\snappy-java-1.1.7.1.jar;D:\DevelopFiles\Maven\m2\com\alibaba\fastjson\1.2.47\fastjson-1.2.47.jar;D:\DevelopFiles\Maven\m2\org\apache\commons\commons-lang3\3.8.1\commons-lang3-3.8.1.jar com.unicom.AlarmQueryKafkaApplication
 
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.0.RELEASE)
2018-10-31 19:53:47.061  INFO 14260 --- [           main] com.unicom.AlarmQueryKafkaApplication    : Starting AlarmQueryKafkaApplication on SHNWANGC260 with PID 14260 (D:\workspace\IDEA\chinaunicom\alarm-query-kafka\target\classes started by wangc260 in D:\workspace\IDEA\chinaunicom)
2018-10-31 19:53:47.068  INFO 14260 --- [           main] com.unicom.AlarmQueryKafkaApplication    : No active profile set, falling back to default profiles: default
2018-10-31 19:53:48.299  INFO 14260 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.kafka.annotation.KafkaBootstrapConfiguration' of type [org.springframework.kafka.annotation.KafkaBootstrapConfiguration$$EnhancerBySpringCGLIB$$60ef0a74] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-10-31 19:53:48.524  WARN 14260 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springConsumer' defined in file [D:\workspace\IDEA\chinaunicom\alarm-query-kafka\target\classes\com\unicom\kafka\SpringConsumer.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchFactory' defined in class path resource [com/unicom/kafka/kafkaConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.kafka.config.KafkaListenerContainerFactory]: Factory method 'batchFactory' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory.getContainerProperties()Lorg/springframework/kafka/listener/ContainerProperties;
2018-10-31 19:53:48.536  INFO 14260 --- [           main] ConditionEvaluationReportLoggingListener : 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-10-31 19:53:48.551 ERROR 14260 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call the method org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory.getContainerProperties()Lorg/springframework/kafka/listener/ContainerProperties; but it does not exist. Its class, org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory, is available from the following locations:
    jar:file:/D:/DevelopFiles/Maven/m2/org/springframework/kafka/spring-kafka/2.1.7.RELEASE/spring-kafka-2.1.7.RELEASE.jar!/org/springframework/kafka/config/ConcurrentKafkaListenerContainerFactory.class
It was loaded from the following location:
    file:/D:/DevelopFiles/Maven/m2/org/springframework/kafka/spring-kafka/2.1.7.RELEASE/spring-kafka-2.1.7.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory
Process finished with exit code 1

SpringBoot整合kafka问题的注意事项

要想外网的机器可以连接成功需要在kafka的server.properties配置文件中需要如下配置

这个需要注意一下,填写主机IP的时候不能写localhost,如果这样写外边的主机是无法连接kafka的,需要标明具体的机器外网IP。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯