V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ChunkitAu
V2EX  ›  问与答

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

  •  
  •   ChunkitAu · 2020-01-16 16:57:08 +08:00 · 1579 次点击
    这是一个创建于 1554 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在 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)"

    求解

    2 条回复    2020-01-17 10:16:56 +08:00
    MetalCore
        1
    MetalCore  
       2020-01-16 17:06:29 +08:00
    你大概是开启了 springboot devtools,导致类的类加载器不一样,你搜下就知道相关问题了
    xiaoxinshiwo
        2
    xiaoxinshiwo  
       2020-01-17 10:16:56 +08:00
    一楼正解
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2719 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:22 · PVG 08:22 · LAX 17:22 · JFK 20:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.