【Azure Event Hub】解决Event Hub SDK出现无法识别 com.azure.core.client.traits.TokenCredentialTrait 错误

问题描述

使用Service Bus SDK编写消费端应用时,遇见了错误信息:

SDK版本

    <dependency>
      <groupId>com.azure</groupId>
      <artifactId>azure-messaging-eventhubs</artifactId>
      <version>5.4.0</version>
    </dependency>
    <dependency>
      <groupId>com.azure</groupId>
      <artifactId>azure-messaging-eventhubs-checkpointstore-blob</artifactId>
      <version>1.14.0</version>
    </dependency>
    <dependency>
      <groupId>com.azure</groupId>
      <artifactId>azure-identity</artifactId>
      <version>1.2.2</version>
      <scope>compile</scope>
    </dependency>

错误信息

Exception in thread "main" java.lang.NoClassDefFoundError: com/azure/core/client/traits/TokenCredentialTrait
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        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)
        at com.example.App.main(App.java:86)
Caused by: java.lang.ClassNotFoundException: com.azure.core.client.traits.TokenCredentialTrait
        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)
        ... 13 more

以上问题,如何解答呢?

 

问题解答

这个错误其实非常明显,就是缺少 azure.core 依赖。 在pom.xml文件中,添加上如下依赖即可解决问题。

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

 

 

参考资料

TokenCredentialTrait not found even when used : https://stackoverflow.com/questions/71617941/tokencredentialtrait-not-found-even-when-used

 

 

posted @ 2024-04-25 20:51  路边两盏灯  阅读(24)  评论(0编辑  收藏  举报