【问题标题】:Spring Boot migration from 2.3.6.RELEASE to 2.4.0 and json ClassCastExceptionSpring Boot 从 2.3.6.RELEASE 迁移到 2.4.0 和 json ClassCastException
【发布时间】:2021-03-08 18:29:48
【问题描述】:

我有一个 Java 项目,它依赖于 SpringBoot 版本 2.3.6.RELEASE。但是,我在尝试升级到 2.4.0 版本时遇到了麻烦。在项目中没有其他任何改变,只有 SpringBoot 的版本。从那时起,应用程序抛出以下错误消息:

Caused by: java.lang.ClassCastException: com.nimbusds.jose.shaded.json.JSONObject cannot be cast to net.minidev.json.JSONObject

我对 maven 依赖树 (mvn dependency:tree) 做了一些比较,发现可能对 nimbus-jose-jwtjson-smart 进行了一些重大更改> 库。

2.3.6.发布

[INFO] +- org.springframework.security:spring-security-oauth2-jose:jar:5.3.5.RELEASE:compile
[INFO] |  +- com.nimbusds:nimbus-jose-jwt:jar:8.19:compile (version managed from 8.20.1)
[INFO] |  |  +- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile
[INFO] |  |  \- net.minidev:json-smart:jar:1.3.1:provided (scope managed from compile)
[INFO] |  +- org.springframework.security:spring-security-core:jar:5.3.5.RELEASE:compile

2.4.0

[INFO] +- org.springframework.security:spring-security-oauth2-jose:jar:5.4.1:compile
[INFO] |  +- com.nimbusds:nimbus-jose-jwt:jar:9.1.2:compile (version managed from 9.0.1)
[INFO] |  |  \- com.github.stephenc.jcip:jcip-annotations:jar:1.0-1:compile
[INFO] |  +- org.springframework.security:spring-security-core:jar:5.4.1:compile

如上所示,nimbus-jose-jwt 已从 8.19 更新到 9.1.2。此外,json-smart 在 2.4.0 中不再是 nimbus-jose-jwt 的一部分。

根本原因可能是这个变化https://connect2id.com/blog/nimbus-jose-jwt-9 但是,应该怎么做才能防止这个异常呢?

【问题讨论】:

  • 你好,你能展示一些你的代码吗?特别是如果抛出异常的行在您自己的代码库下。
  • 找出什么在使用旧的依赖并升级它。你不能“仅仅”升级 1 个版本,你必须考虑这些事情。可能是您正在使用的某些代码(或另一个库)使用了旧代码。要么升级它,要么修改代码。如果不是,你不能使用 Spring Boot 2.4(还)。

标签: spring spring-boot nimbus-jose-jwt


【解决方案1】:

您可以通过在 pom 中显式添加旧版本来覆盖 jar nimbus-jose-jwt 和 json-smart 的默认版本。

【讨论】:

    【解决方案2】:

    请参考这里:https://github.com/Azure/azure-sdk-for-java/issues/14898

    就我而言 - 我必须升级到 2.5.7 Springboot 版本,而 SB-2.5.7 附带的 nimbus-jose-jwt:jar 版本是 9.10.1。

        org.springframework.security:spring-security-oauth2-jose:jar:5.5.3:compile
    [INFO] |  +- (org.springframework.security:spring-security-core:jar:5.5.3:compile - version managed from 4.2.15.RELEASE; omitted for duplicate)
    [INFO] |  +- (org.springframework.security:spring-security-oauth2-core:jar:5.5.3:compile - omitted for duplicate)
    [INFO] |  +- (org.springframework:spring-core:jar:5.3.13:compile - version managed from 5.3.11; omitted for duplicate)
    [INFO] |  \- com.nimbusds:nimbus-jose-jwt:jar:9.10.1:compile
    

    将 nimbus-jose-jwt 降级到 8.20 后,应用开始运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-03
      • 2017-08-19
      • 2023-02-06
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 2019-01-07
      • 2020-11-18
      相关资源
      最近更新 更多