融合Kafka java.lang.ClassNotFoundException:io.confluent.kafka.schemaregistry.json.jackson.Jackson

f3temu5u  于 2023-01-07  发布在  Java
关注(0)|答案(1)|浏览(115)

因为我使用蚂蚁项目,我需要从这里kafka-schema-registry的lib jar,使用jar,但得到错误丢失

java.lang.ClassNotFoundException: io.confluent.kafka.schemaregistry.json.jackson.Jackson

如果我尝试用Maven项目构建

<!-- https://mvnrepository.com/artifact/io.confluent/kafka-schema-registry -->
<dependency>
    <groupId>io.confluent</groupId>
    <artifactId>kafka-schema-registry</artifactId>
    <version>7.3.1</version>
</dependency>

可以导入类io.confluent.kafka.schemaregistry.json.jackson.Jackson

import io.confluent.kafka.schemaregistry.json.jackson.Jackson;

为什么. jar中的类不见了?
导入库:

import io.confluent.kafka.serializers.json.KafkaJsonSchemaSerializer;
import io.confluent.kafka.serializers.json.KafkaJsonSchemaSerializerConfig;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.IntegerSerializer;

配置:

Properties props = new Properties();
                props.put("bootstrap.servers", url);
                props.put("linger.ms", 1);
                props.put("max.block.ms", 10000);
                props.put("group.id", "billtrust");
                props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, IntegerSerializer.class.getName());
                props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaJsonSchemaSerializer.class.getName());
                props.put(KafkaJsonSchemaSerializerConfig.SCHEMA_REGISTRY_URL_CONFIG, "http://localhost:8081");
                Producer<String, Payment> producer = new KafkaProducer<String, Payment>(props);
                ProducerRecord<String, Payment> record = new ProducerRecord<String, Payment>(topic, uuid, message);

                producer.send(record);

完整错误日志:

org.apache.kafka.common.KafkaException: Failed to construct kafka producer
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:468)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:291)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:318)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:303)
        at api.kafka.Kafka.sendPayment(Kafka.java:80)
        at apiBiling.Prepaid.TopupPlan.TopupwPlan(TopupPlan.java:382)
        at apiBiling.Prepaid.TopupPlan.execute(TopupPlan.java:86)
        at org.jpublish.action.ActionWrapper.execute(ActionWrapper.java:68)
        at org.jpublish.page.PageInstance.executeActions(PageInstance.java:272)
        at org.jpublish.Page.executeActions(Page.java:245)
        at org.jpublish.servlet.JPublishServlet.doPost(JPublishServlet.java:413)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.kafka.common.KafkaException: Could not instantiate class io.confluent.kafka.serializers.json.KafkaJsonSchemaSerializer
        at org.apache.kafka.common.utils.Utils.newInstance(Utils.java:396)
        at org.apache.kafka.common.config.AbstractConfig.getConfiguredInstance(AbstractConfig.java:401)
        at org.apache.kafka.common.config.AbstractConfig.getConfiguredInstance(AbstractConfig.java:436)
        at org.apache.kafka.common.config.AbstractConfig.getConfiguredInstance(AbstractConfig.java:421)
        at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:394)
        ... 34 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.apache.kafka.common.utils.Utils.newInstance(Utils.java:392)
        ... 38 more
Caused by: java.lang.NoClassDefFoundError: io/confluent/kafka/schemaregistry/json/jackson/Jackson
        at io.confluent.kafka.serializers.json.AbstractKafkaJsonSchemaSerializer.<init>(AbstractKafkaJsonSchemaSerializer.java:47)
        at io.confluent.kafka.serializers.json.KafkaJsonSchemaSerializer.<init>(KafkaJsonSchemaSerializer.java:41)
        ... 43 more
Caused by: java.lang.ClassNotFoundException: io.confluent.kafka.schemaregistry.json.jackson.Jackson
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1407)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1215)
        ... 45 more
java.lang.Exception: org.apache.kafka.common.KafkaException: Failed to construct kafka producer
e4yzc0pl

e4yzc0pl1#

序列化程序与核心注册表模块分离。
你错过了这些

<dependency>
    <groupId>io.confluent</groupId>
    <artifactId>kafka-json-schema-provider</artifactId>
    <version>7.3.1</version>
</dependency>
<dependency>
    <groupId>io.confluent</groupId>
    <artifactId>kafka-json-schema-serializer</artifactId>
    <version>7.3.1</version>
</dependency>

相关问题