在 Weblogic 上部署 OpenID Azure AD java 网络应用程序时出现 NoClassDefFoundError

NoClassDefFoundError while deploying a OpenID Azure AD java web-app on Weblogic

我正在尝试使用 OpenIDConnect 方法为我的网络应用程序集成 Azure AD。当我尝试在 weblogic 上部署构建的 ear 文件时,我得到了

的 NoClassDefFound

com.nimbusds.openid.connect.sdk.AuthenticationSuccessResponse

。我已将 oauth2-oidc-sdk-5.24.1.jar 包含在 web-inf/lib 文件夹中,还验证了它实际上存在于 ear 文件中但应用程序部署抱怨找不到这个 class.

失败

我发现了类似的问题 here。所以我尝试将 oauth2-oidc-sdk-5.24.1.jar 和 gson jar 文件与我的 java 网络应用程序一起部署为库,但这也没有帮助。

如果我能得到任何指示或建议来克服这个错误,我将不胜感激。

部署期间的完整堆栈跟踪:

Caused By: java.lang.NoClassDefFoundError: com/nimbusds/openid/connect/sdk/AuthenticationSuccessResponse
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2436)
        at java.lang.Class.getDeclaredMethods(Class.java:1793)
        at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.getMethods(BaseJ2eeAnnotationProcessor.java:1055)
        at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.getMethods(BaseJ2eeAnnotationProcessor.java:1043)
        at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.processJ2eeAnnotations(BaseJ2eeAnnotationProcessor.java:99)
        at weblogic.j2ee.dd.xml.J2eeAnnotationProcessor.processJ2eeAnnotations(J2eeAnnotationProcessor.java:37)
        at weblogic.servlet.internal.WebAnnotationProcessorImpl.processFilters(WebAnnotationProcessorImpl.java:239)
        at weblogic.servlet.internal.WebAnnotationProcessorImpl.processJ2eeAnnotations(WebAnnotationProcessorImpl.java:210)
        at weblogic.servlet.internal.WebAnnotationProcessorImpl.processAnnotations(WebAnnotationProcessorImpl.java:105)
        at weblogic.servlet.internal.WebAppServletContext.processAnnotations(WebAppServletContext.java:1370)
        at weblogic.servlet.internal.WebAppServletContext.<init>(WebAppServletContext.java:450)
        at weblogic.servlet.internal.WebAppServletContext.<init>(WebAppServletContext.java:494)
        at weblogic.servlet.internal.HttpServer.loadWebApp(HttpServer.java:418)
        at weblogic.servlet.internal.WebAppModule.registerWebApp(WebAppModule.java:976)
        at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:384)
        at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)
        at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
        at weblogic.application.internal.flow.DeploymentCallbackFlow.next(DeploymentCallbackFlow.java:517)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
        at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:159)
        at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:45)
        at weblogic.application.internal.BaseDeployment.next(BaseDeployment.java:648)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
        at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:191)
        at weblogic.application.internal.EarDeployment.prepare(EarDeployment.java:59)
        at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:154)
        at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:208)
        at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:98)
        at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:747)
        at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1216)
        at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:250)
        at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159)
        at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:171)

#####################################

更新 2021/06/02

为了解决版本兼容性问题,我不得不选择以下特定版本的依赖项以使其不会为 JDK1.6 抛出错误,并且 microsoft adal4j 必须在 JDK6 中重新编译( jdk1.7及以上版本支持adal4j jar)

    <groupId>com.nimbusds</groupId>
    <artifactId>nimbus-jose-jwt</artifactId>
    <classifier>jdk16</classifier>
    <version>5.9</version>
    

    <groupId>com.nimbusds</groupId>
    <artifactId>oauth2-oidc-sdk</artifactId>
    <classifier>jdk16</classifier>
    <version>5.24.1</version>
    </dependency>

如果 JDK 是 1.7,下面是适合我的具体版本:

        <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>adal4j</artifactId>
        <version>1.6.0</version>
        </dependency>
    
        <dependency>
        <groupId>com.nimbusds</groupId>
        <artifactId>oauth2-oidc-sdk</artifactId>
        <version>5.24.1</version>
        </dependency>
        
        <dependency>
        <groupId>com.nimbusds</groupId>
        <artifactId>nimbus-jose-jwt</artifactId>
        <version>7.8</version>
        </dependency>

希望这对在 JDK1.6 和 JDK1.7

上遇到类似错误的人有所帮助

这通常是由于版本不兼容造成的。您可以尝试不同版本的 oauth2-oidc-sdk,直到找到兼容的包。

或者你也可以更改spring的版本,达到评论中提到的版本兼容的目的