ChunkitAu
V2EX  ›  问与答

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

  •  
  •   ChunkitAu · Jan 16, 2020 · 2371 views
    This topic created in 2316 days ago, the information mentioned may be changed or developed.

    在 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 replies    2020-01-17 10:16:56 +08:00
    MetalCore
        1
    MetalCore  
       Jan 16, 2020
    你大概是开启了 springboot devtools,导致类的类加载器不一样,你搜下就知道相关问题了
    xiaoxinshiwo
        2
    xiaoxinshiwo  
       Jan 17, 2020
    一楼正解
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3493 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 70ms · UTC 04:47 · PVG 12:47 · LAX 21:47 · JFK 00:47
    ♥ Do have faith in what you're doing.