在Java中使用融合的Avro序列化程序-NoSuchFieldError:PASSWORD

时间:2019-06-26 17:14:41

标签: java apache-kafka confluent

我在Java中使用融合的Avro生产器,但是在运行它时出现问题。我添加了所有必需的jar。没有任何线索我错过了什么?

Exception in thread "main" java.lang.NoSuchFieldError: PASSWORD
    at io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig.baseConfigDef(AbstractKafkaAvroSerDeConfig.java:92)
    at io.confluent.kafka.serializers.KafkaAvroSerializerConfig.<clinit>(KafkaAvroSerializerConfig.java:28)
    at io.confluent.kafka.serializers.KafkaAvroSerializer.configure(KafkaAvroSerializer.java:48)
    at org.apache.kafka.common.serialization.ExtendedSerializer$Wrapper.configure(ExtendedSerializer.java:60)
    at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:341)
    at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:302)

我尝试了以下配置。

Properties prop = new Properties();
        prop.put("bootstrap.servers", "localhost:9092");
        prop.put("schema.registry.url", "http://localhost:8081");
        //prop.put("basic.auth.user.info", "");
        prop.put("ssl.keystore.type",null);
        prop.put("acks", "all");
        prop.put("retries", "0");
        prop.put("key.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer");
        prop.put("value.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer");
        prop.put("group.id", "test");
  

这些是我使用它的依赖项。所有具有最新版本的jar。

        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>kafka-schema-registry</artifactId>
            <version>4.1.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.confluent/common-config -->
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>common-config</artifactId>
            <version>3.3.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.confluent/common-utils -->
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>common-utils</artifactId>
            <version>3.3.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.confluent/kafka-connect-avro-converter -->
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>kafka-connect-avro-converter</artifactId>
            <version>5.2.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.confluent/kafka-schema-registry-client -->
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>kafka-schema-registry-client</artifactId>
            <version>5.2.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.confluent.kafka/connect-utils -->
        <dependency>
            <groupId>io.confluent.kafka</groupId>
            <artifactId>connect-utils</artifactId>
            <version>0.1.18</version>
        </dependency>

        <dependency>
            <groupId>io.confluent.kafka</groupId>
            <artifactId>connect-checkstyle</artifactId>
            <version>0.1.18</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.confluent/rest-utils -->
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>rest-utils</artifactId>
            <version>4.1.0</version>
        </dependency>

1 个答案:

答案 0 :(得分:0)

我在混合版本时看到此错误。这些也不是最新版本,因为MvnReposistory不会缓存实际的Confluent存储库。

您只需要这个

    <dependency>
        <groupId>io.confluent</groupId>
        <artifactId>kafka-avro-serializer</artifactId>
        <version>5.2.1</version>
    </dependency>

https://docs.confluent.io/current/app-development/index.html#native-clients-with-serializers

删除其余依赖项