Java 同类型的对象无法强转????

2020-01-16 16:57:08 +08:00
 ChunkitAu

在 SpringBoot 整合 Shiro 时报错

java.lang.ClassCastException: com.chunkit.show_web.entity.User cannot be cast to com.chunkit.show_web.entity.User

报异常的句子 user = (User)((SimplePrincipalCollection) attribute).getPrimaryPrincipal();

attribute::

attribute = {SimplePrincipalCollection@8525} "User(userid=3, username=admin, password=4af009edcc2fc527d84e93f6b7f04b8c1c22607258776512a1f2ab7b86eef309, accountname=admin)" realmPrincipals = {LinkedHashMap@8565} size = 1 "com.chunkit.show_web.auth.shiro.CustomRealm_0" -> {LinkedHashSet@8574} size = 1 cachedToString = "User(userid=3, username=admin, password=4af009edcc2fc527d84e93f6b7f04b8c1c22607258776512a1f2ab7b86eef309, accountname=admin)"

求解

1631 次点击
所在节点    问与答
2 条回复
MetalCore
2020-01-16 17:06:29 +08:00
你大概是开启了 springboot devtools,导致类的类加载器不一样,你搜下就知道相关问题了
xiaoxinshiwo
2020-01-17 10:16:56 +08:00
一楼正解

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/638489

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX