java.lang.AbstractMethodError: I get this exception when I am trying to initiate an outbound voice call using nexmo(vonage) API

java.lang.AbstractMethodError: I get this exception when I am trying to initiate an outbound voice call using nexmo(vonage) API

My pom.xml 用于所有相关依赖项。没有其他依赖项在内部使用以下依赖项。

<dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.9</version>
    </dependency>
<dependency>
      <groupId>com.sparkjava</groupId>
      <artifactId>spark-core</artifactId>
      <version>2.6.0</version>
    </dependency>
    <dependency>
      <groupId>com.vonage</groupId>
      <artifactId>client</artifactId>
      <version>6.0.0</version>
    </dependency>

    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-api</artifactId>
      <version>0.11.0</version>
    </dependency>
    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-impl</artifactId>
      <version>0.11.0</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-jackson</artifactId>
      <version>0.11.0</version>
      <scope>runtime</scope>
    </dependency>
<dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt</artifactId>
      <version>0.9.1</version>
    </dependency>

Java 使用 vonage SDK 发起呼出语音呼叫的代码。

VonageClient client = VonageClient.builder().applicationId(APPLICATION_ID).privateKeyContents(PRIVATE_KEY).build();
    
Ncco ncco = new Ncco(TalkAction.builder(MESSAGE).voiceName(VOICE_TYPE).build());
CallEvent callEvent=client.getVoiceClient().createCall(newCall(TO_NUMBER,FROM_NUMBER, ncco));

执行代码时抛出异常。

java.lang.AbstractMethodError: Receiver class io.jsonwebtoken.impl.DefaultJwtBuilder does not define or inherit an implementation of the resolved method 'abstract io.jsonwebtoken.JwtBuilder signWith(java.security.Key, io.jsonwebtoken.SignatureAlgorithm)' of interface io.jsonwebtoken.JwtBuilder. at com.nexmo.jwt.JwtGenerator.generate(JwtGenerator.kt:49) ~[jwt-1.0.1.jar:?] at com.nexmo.jwt.Jwt.generate(Jwt.kt:44) ~[jwt-1.0.1.jar:?] at com.nexmo.jwt.Jwt.generate$default(Jwt.kt:43) ~[jwt-1.0.1.jar:?] at com.nexmo.jwt.Jwt.generate(Jwt.kt) ~[jwt-1.0.1.jar:?] at com.vonage.client.auth.JWTAuthMethod.apply(JWTAuthMethod.java:43) ~[client-6.0.0.jar:6.0.0] at com.vonage.client.AbstractMethod.applyAuth(AbstractMethod.java:127) ~[client-6.0.0.jar:6.0.0] at com.vonage.client.AbstractMethod.execute(AbstractMethod.java:73) ~[client-6.0.0.jar:6.0.0] at com.vonage.client.voice.CallsEndpoint.post(CallsEndpoint.java:57) ~[client-6.0.0.jar:6.0.0] at com.vonage.client.voice.VoiceClient.createCall(VoiceClient.java:61) ~[client-6.0.0.jar:6.0.0] at com.senpiper.core.listener.VoiceCallListener.listen(VoiceCallListener.java:37) ~[classes/:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?] at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]

问题参考:

<dependency>
    <groupId>io.jsonwebtoken</groupId>
    <artifactId>jjwt</artifactId>
    <version>0.9.1</version>        
</dependency>

删除此依赖项将解决您的问题。这个包被前面的三个包所取代,它们是同一个包的模块化版本,请参阅 v0.10.0 release notes for details POM 文件中的以下内容就足够了:

<dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-api</artifactId>
      <version>0.11.0</version>
</dependency>
<dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-impl</artifactId>
      <version>0.11.0</version>
      <scope>runtime</scope>
</dependency>
<dependency>
      <groupId>io.jsonwebtoken</groupId>
      <artifactId>jjwt-jackson</artifactId>
      <version>0.11.0</version>
      <scope>runtime</scope>
</dependency>

Vonage SDK 依赖于 jjwt v0.10.5,但您的应用程序正在使用的方法是在 v0.10.0 中引入的 - 当参数被翻转时。在处理依赖项的副本时,Maven 可能有点古怪。在这种情况下,因为您明确引用了 jjwt0.9.1,所以它引入了不兼容的版本。如果我不得不在黑暗中拍摄,我猜想对非模块化 jjwt 包的引用先于其他依赖项 - 这就是为什么它被引入而不是其他的原因。

无论如何 - 只需删除对旧 jjwt 包的引用 - 这将解决您的问题。