qq_42164959
Vincent_Leee丶
采纳率75%
2019-11-26 13:11

求救!kafka maven依赖冲突问题

小弟目前在写毕业设计项目,其中涉及到kafka javaapi的一段代码:

import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;

public void sendMessage(AppLogEntity e) {
        //创建配置对象
        Properties props = new Properties();
        props.put("metadata.broker.list", "192.168.72.182:9092");
        props.put("serializer.class", "kafka.serializer.StringEncoder");
        props.put("request.required.acks", "1");

        //创建生产者

        Producer<Integer, String> producer = new Producer<Integer, String>(new ProducerConfig(props));
        sendSingleLog(producer,Constants.TOPIC_APP_STARTUP,e.getAppStartupLogs());
        sendSingleLog(producer,Constants.TOPIC_APP_ERRROR,e.getAppErrorLogs());
        sendSingleLog(producer,Constants.TOPIC_APP_EVENT,e.getAppEventLogs());
        sendSingleLog(producer,Constants.TOPIC_APP_PAGE,e.getAppPageLogs());
        sendSingleLog(producer,Constants.TOPIC_APP_USAGE,e.getAppUsageLogs());

        //发送消息
        producer.close();
    }

框架是SSM,启动后报错
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'collectLogController':
Failed to introspect bean class [com.automan.applogs.collect.web.controller.CollectLogController] for lookup method metadata:
could not find class that it depends on; nested exception is
java.lang.NoClassDefFoundError: kafka/javaapi/producer/Producer
再往下看,即是
Caused by: java.lang.ClassNotFoundException: kafka.javaapi.producer.Producer

我第一反应是去看pom文件,发现依赖都没有问题,但点开详细dependency后,发现kafka的依赖中scala版本冲突了,
图片说明

查询了各种办法都解决不掉,也不知道是不是这个问题导致上述报错,特来求救,感激不尽~~

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答