java 无法使用用户管理的身份凭据从Azure函数应用程序发送事件网格事件

rbl8hiat  于 2023-09-29  发布在  Java
关注(0)|答案(1)|浏览(111)

当尝试使用UserManagedIdentity Credential将数据发送到Azure EventGrid时,会引发ClassNotFoundException: com.azure.core.util.tracing.TracerProvider

import com.azure.identity.ManagedIdentityCredentialBuilder;
import com.azure.messaging.eventgrid.EventGridEvent;
import com.azure.messaging.eventgrid.EventGridPublisherClient;
import com.azure.messaging.eventgrid.EventGridPublisherClientBuilder;
import com.azure.core.credential.TokenCredential;

TokenCredential managedIdentityCredentialUserAssigned = new ManagedIdentityCredentialBuilder().clientId(System.getenv("MANAGED_IDENTITY_CLIENT_ID")).build();
EventGridPublisherClient<EventGridEvent> eventGridEventClient = new EventGridPublisherClientBuilder()
     .endpoint(System.getenv("EVENTGRID_SYNC_TOPIC_ENDPOINT")).credential(managedIdentityCredentialUserAssigned).buildEventGridEventPublisherClient();
Exception: ClassNotFoundException: com.azure.core.util.tracing.TracerProvider
Caused by: java.lang.NoClassDefFoundError: com/azure/core/util/tracing/TracerProvider
    at com.azure.messaging.eventgrid.EventGridPublisherClientBuilder.buildAsyncClient(EventGridPublisherClientBuilder.java:204)
    at com.azure.messaging.eventgrid.EventGridPublisherClientBuilder.buildClient(EventGridPublisherClientBuilder.java:232)
    at com.azure.messaging.eventgrid.EventGridPublisherClientBuilder.buildEventGridEventPublisherClient(EventGridPublisherClientBuilder.java:393)
    at com.cie.poc.managed.identity.function.service.ManagedIdentityEventGridService.sendEvent(ManagedIdentityEventGridService.java:39)
    at com.cie.poc.managed.identity.function.SaveDataToBlob.apply(SaveDataToBlob.java:56)
    at com.cie.poc.managed.identity.function.SaveDataToBlob.apply(SaveDataToBlob.java:22)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.invokeFunctionAndEnrichResultIfNecessary(SimpleFunctionRegistry.java:897)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.invokeFunction(SimpleFunctionRegistry.java:853)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.doApply(SimpleFunctionRegistry.java:708)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:551)
    at org.springframework.cloud.function.adapter.azure.FunctionInvoker.handleRequest(FunctionInvoker.java:129)
    at com.cie.poc.managed.identity.function.SaveDataToBlobHandler.run(SaveDataToBlobHandler.java:32)
    ... 18 more
Caused by: java.lang.ClassNotFoundException: com.azure.core.util.tracing.TracerProvider
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 30 more

这些是我的azure函数应用程序的pom.xml中定义的相关依赖项及其版本。

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-messaging-eventgrid</artifactId>
    <version>4.18.0</version>
</dependency>
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-identity</artifactId>
    <version>1.7.3</version>
</dependency>
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-eventgrid</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-core</artifactId>
    <version>1.35.0</version>
</dependency>

Sping Boot 版本:2.7.8,Java版本:11
如果您知道如何解决此问题,请提供帮助。提前感谢!

gojuced7

gojuced71#

在使用 1.42.0 版本的 azure-core 后,我能够解决此问题。我在我的函数应用程序的pom.xml文件中添加了以下依赖项。

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-core</artifactId>
    <version>1.42.0</version>
</dependency>

我以前有 azure-core 1.35.0,它不包含TracerProvider类。

相关问题