我有一个 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-jwt和json-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 但是,为了防止这个异常应该怎么做呢?