尝试与 azure AuthenticationResult 连接,但出现错误 java.lang.NoClassDefFoundError: com/nimbusds/jwt/JWTParser

Rah*_*i07 5 java azure spring-boot

尝试通过休息服务调用与 azure AuthenticationResult 连接,但收到错误消息

{“代码”:500,“消息”:“java.lang.NoClassDefFoundError:com / nimbusds / jwt / JWTParser”}

private static AuthenticationResult getAccessTokenFromUserCredentials(String username, String password)
        throws Exception {
    AuthenticationContext context;
    AuthenticationResult result;
    ExecutorService service = null;
    try {
        service = Executors.newFixedThreadPool(1);
        context = new AuthenticationContext(AUTHORITY, false, service);
        Future<AuthenticationResult> future = context.acquireToken("https://graph.microsoft.com", CLIENT_ID, username, password, null);

        result = future.get();
    } finally {
        service.shutdown();
    }

    if (result == null) {
        throw new ServiceUnavailableException("authentication result was null");
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)

小智 3

我有类似的错误。这是由于运行时依赖类不可用。尝试添加此nimbus-jose-jwt JAR 版本 4.2

链接是https://jar-download.com/artifacts/com.nimbusds/nimbus-jose-jwt/4.2/source-code

找出此错误的方法是,使用类名 com.nimbusds.jwt.JWTParser jar 进行搜索,并且在添加之前必须在 jar 中找到该类。尝试一下并告诉我们。