生产者初始化问题无法初始化类org.apache.kafka.clients.producer.producerconfig

nwnhqdif  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(605)

我试图创建一个Kafka在卡拉夫4.0.3制片人。

ClassLoader currentLoader; 
try{
    currentLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(null);
    Properties props = new Properties();
    props.put("bootstrap.servers","localhost:9092");
    props.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer");
    props.put("key.serializer","org.apache.kafka.common.serialization.IntegerSerializer");

    KafkaProducer<String,String> producer = new KafkaProducer<String,String>(props);
    Thread.currentThread().setContextClassLoader(currentLoader);
    producer.close();

我的 pom.xml 包含,

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>0.9.0.0</version>
</dependency>

在部署代码时,我得到以下错误,

2016-05-09 14:18:12,127 | ERROR | nsole user karaf | ShellUtil                        | 44 - org.apache.karaf.shell.core - 4.0.3 | Exception caught while executing command
org.apache.karaf.shell.support.MultiException: Error executing command on bundles:
Error starting bundle143: Activator start error in bundle KafkaArtifact [143].
at org.apache.karaf.shell.support.MultiException.throwIf(MultiException.java:61)
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:69)[24:org.apache.karaf.bundle.core:4.0.3]
at org.apache.karaf.bundle.command.BundlesCommand.execute(BundlesCommand.java:54)[24:org.apache.karaf.bundle.core:4.0.3]
at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:270)[44:org.apache.karaf.shell.core:4.0.3]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_66]
Caused by: java.lang.Exception: Error starting bundle143: Activator start error in bundle KafkaArtifact [143].
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:66)[24:org.apache.karaf.bundle.core:4.0.3]
... 12 more
Caused by: org.osgi.framework.BundleException: Activator start error in bundle KafkaArtifact [143].
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2276)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.karaf.bundle.command.Start.executeOnBundle(Start.java:38)[24:org.apache.karaf.bundle.core:4.0.3]
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:64)[24:org.apache.karaf.bundle.core:4.0.3]
... 12 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.kafka.clients.producer.ProducerConfig
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:181)
at com.KafkaSample.KafkaArtifact.Producer.<init>(Producer.java:24)
at com.KafkaSample.KafkaArtifact.KafkaConsumerProducerDemo.start(KafkaConsumerProducerDemo.java:9)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2226)
... 16 more

我在下面的链接中也尝试过解决方法,
karaf-kafka osgi捆绑包-制作人问题
但仍然得到同样的错误。

lnxxn5zx

lnxxn5zx1#

我知道这是一个三个月前的问题。就连我也被制片人的问题困住了。经过两天的挖掘,我偶然发现了一个jira问题,有人已经提到了这个问题,解决方案已经修补,但将在camel库的2.18.0版本中提供。然而,为了解决这个问题,我克隆了这个camel存储库,并为我的项目构建了所需的组件。在components文件夹下,选择所需的组件并执行maven clean package,以在目标目录中生成jar。
还有一件事,在编译camel核心子项目时。它执行很多测试用例,您可能不需要它,所以只需在最后一行属性中将“”替换为“org/apache/camel/***.java”。希望这有帮助。

相关问题