在线程"main" java.lang.NoClassDefFoundError中获取异常: com/azure/core/util/ClientOptions



我正在eclipse中使用java测试自动化azure事件中心函数。

我正在尝试运行EventHub函数的接收器应用程序。

以下是输出:

Exception in thread "main" java.lang.NoClassDefFoundError: com/azure/core/util/ClientOptions
at com.azure.storage.blob.BlobContainerClientBuilder.<init>(BlobContainerClientBuilder.java:73)
at AzureEventHubTest.Receiver.main(Receiver.java:44)
Caused by: java.lang.ClassNotFoundException: com.azure.core.util.ClientOptions
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more        

这是代码:

package AzureEventHubTest;

import com.azure.messaging.eventhubs.EventHubClientBuilder;
import com.azure.messaging.eventhubs.EventProcessorClient;
import com.azure.messaging.eventhubs.EventProcessorClientBuilder;
import com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore;
import com.azure.messaging.eventhubs.models.ErrorContext;
import com.azure.messaging.eventhubs.models.EventContext;
import com.azure.storage.blob.BlobContainerAsyncClient;
import com.azure.storage.blob.BlobContainerClientBuilder;
import com.azure.messaging.eventhubs.checkpointstore.blob.*;
import java.util.function.Consumer;
import java.util.concurrent.TimeUnit;
import com.azure.core.util.*;
import com.microsoft.azure.eventhubs.ConnectionStringBuilder;
import com.microsoft.azure.eventhubs.EventData;
import com.microsoft.azure.eventhubs.EventHubClient;
import com.microsoft.azure.eventhubs.EventHubException;
public class  Receiver {
private static final String EH_NAMESPACE_CONNECTION_STRING = "//test";
//sb://eqix-es-dev-eventhub.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=y3cVul6e5HRi4h30eFNwKBx3YLHaV+A7kQSX40TIeZc=";
private static final String eventHubName = "//test";
private static final String STORAGE_CONNECTION_STRING = "//test";
private static final String STORAGE_CONTAINER_NAME = "//test";


public static final java.util.function.Consumer<EventContext> PARTITION_PROCESSOR = eventContext -> {
System.out.printf("Processing event from partition %s with sequence number %d with body: %s %n", 
eventContext.getPartitionContext().getPartitionId(), eventContext.getEventData().getSequenceNumber(), eventContext.getEventData().getBodyAsString());
if (eventContext.getEventData().getSequenceNumber() % 10 == 0) {
eventContext.updateCheckpoint();
}
};
public static final java.util.function.Consumer<ErrorContext> ERROR_HANDLER = errorContext -> {
System.out.printf("Error occurred in partition processor for partition %s, %s.%n",
errorContext.getPartitionContext().getPartitionId(),
errorContext.getThrowable());
};
public static void main(String[] args) throws Exception {
BlobContainerAsyncClient blobContainerAsyncClient = new BlobContainerClientBuilder()
.connectionString(STORAGE_CONNECTION_STRING)
.containerName(STORAGE_CONTAINER_NAME)
.buildAsyncClient();
EventProcessorClientBuilder eventProcessorClientBuilder = new EventProcessorClientBuilder()
.connectionString(EH_NAMESPACE_CONNECTION_STRING, eventHubName)
.consumerGroup(EventHubClientBuilder.DEFAULT_CONSUMER_GROUP_NAME).processEvent(PARTITION_PROCESSOR)
.processError(ERROR_HANDLER)
.checkpointStore(new BlobCheckpointStore(blobContainerAsyncClient));
EventProcessorClient eventProcessorClient = eventProcessorClientBuilder.buildEventProcessorClient();
System.out.println("Starting event processor");
eventProcessorClient.start();
System.out.println("Press enter to stop.");
System.in.read();
System.out.println("Stopping event processor");
eventProcessorClient.stop();
System.out.println("Event processor stopped.");
System.out.println("Exiting process");
}
}

有人能帮我知道我哪里错了吗?我的代码出了什么问题,或者其他什么问题?我因此陷入困境。

这些是添加的maven依赖项:

包含-azureventhubs依赖项和其他:

<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventhubs-checkpointstore-blob</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-eventhubs</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.0-alpha1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.0-alpha1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.10.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>

ClientOptionsazure-core版本1.9.0中引入,在azure-storage-blob版本12.10.0中使用。

1.1.1版本的azure-messaging-eventhubs-checkpointstore-blob使用了azure-core(1.5.1)的旧版本,该版本没有ClientOptions。因此,在运行时,加载azure-core的旧版本,从而在创建尝试使用ClientOptions类的BlobContainer时生成NoClassDefFoundError

因此,如果将azure-messaging-eventhubs-checkpointstore=blob升级到1.5.0,将azure-messaging-eventhubs升级到5.5.0,则此问题将得到解决。

附带说明一下,您可以将azure-storage-blob从依赖项列表中删除,因为azure-messaging-eventhubs-checkpointstore-blob可转换地包含azure-storage-blob

NoClassDefFoundError是在类不在类路径上时抛出的。你尝试过这里提到的解决方案吗?线程中出现异常';main';java.lang.NoClassDefFoundError:

相关内容

最新更新