未找到类org.apache.kafka.common.serialization.StringSerializer

时间:2017-08-15 21:57:56

标签: java spring apache-kafka spring-xd

我写了一个Kafka制作人,当我在Spring-XD守护进程以外的任何地方执行它时运行良好。

private Properties setProperties () {
    Properties props = new Properties();
    props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,this.getBrokerList());
    props.put(ProducerConfig.ACKS_CONFIG,this.getAcks());
    props.put(ProducerConfig.BATCH_SIZE_CONFIG, this.getBatchSize());
    props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, this.getCompressionCodec());
    props.put(ProducerConfig.RETRIES_CONFIG,this.getRetries());
    props.put(ProducerConfig.LINGER_MS_CONFIG,this.getLinger());
    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,this.getKeySerializer());
    props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,this.getValueSerializer());
    props.put(ProducerConfig.BUFFER_MEMORY_CONFIG,this.getBufferMemoryConfig());
    return props;
}

当我尝试在Spring-XD上运行时,我收到以下错误:

2017-08-15T21:40:05+0000 1.2.1.RELEASE ERROR pool-11-thread-8 consumer.RabbitMQSource - foo-rabbitmq-kafka
org.apache.kafka.common.config.ConfigException: Invalid value org.apache.kafka.common.serialization.StringSerializer for configuration key.serializer: Class org.apache.kafka.common.serialization.StringSerializer could not be found.
    at org.apache.kafka.common.config.ConfigDef.parseType(ConfigDef.java:715) ~[kafka-clients-0.11.0.0.jar!/:na]
    at org.apache.kafka.common.config.ConfigDef.parseValue(ConfigDef.java:460) ~[kafka-clients-0.11.0.0.jar!/:na]
    at org.apache.kafka.common.config.ConfigDef.parse(ConfigDef.java:453) ~[kafka-clients-0.11.0.0.jar!/:na]
    at org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:62) ~[kafka-clients-0.11.0.0.jar!/:na]
    at org.apache.kafka.common.config.AbstractConfig.<init>(AbstractConfig.java:75) ~[kafka-clients-0.11.0.0.jar!/:na]
    at org.apache.kafka.clients.producer.ProducerConfig.<init>(ProducerConfig.java:359) ~[kafka-clients-0.11.0.0.jar!/:na]
    at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:287) ~[kafka-clients-0.11.0.0.jar!/:na]
    at com.foo.dsat.producer.KafkaSink.getProducer(KafkaSink.java:54) ~[foo-rabbit.jar!/:na]
    at com.foo.dsat.producer.KafkaSink.sendMessage(KafkaSink.java:62) ~[foo-rabbit.jar!/:na]
    at com.foo.dsat.consumer.RabbitMQSource$2.handleDelivery(RabbitMQSource.java:90) ~[foo-rabbit.jar!/:na]
    at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149) [amqp-client-4.2.0.jar!/:na]
    at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:100) [amqp-client-4.2.0.jar!/:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
2017-08-15T21:40:05+0000 1.2.1.RELEASE ERROR pool-11-thread-8 consumer.RabbitMQSource - foo-rabbitmq-kafka
org.apache.kafka.common.config.ConfigException: Invalid value org.apache.kafka.common.serialization.StringSerializer for configuration key.serializer: Class org.apache.kafka.common.serialization.StringSerializer could not be found.

我在其他StackOverflow主题中看到了这个问题的解决方案,

Thread.currentThread().setContextClassLoader(null);

但是当我尝试它时,我得到了其他奇怪的错误:

Could not load 'org-xerial-snappy.properties' from classpath:
java.lang.NullPointerException

我在Google上发现此错误,但与较旧的Kafka版本有关,而不是我的版本。

compile group: 'org.apache.kafka', name: 'kafka_2.12', version: '0.11.0.0'

有什么建议吗?

0 个答案:

没有答案