springboot 使用 dev tool 导致 CastException

1、背景

项目使用了 Spring + shiro  实现 权限控制, 使用AOP 对 每个 Controller 进行 log 记录时,需要从 shiro 中 获取 username字段, 问题就这样出现了。

UserDO userDO = (UserDO) SecurityUtils.getSubject().getPrincipal();

出现 java.lang.ClassCastException: 

com.xxx.common.dal.dataobject.UserDO cannot be cast to com.xxx.common.dal.dataobject.UserDO

心里一惊,这怎么回事,这段代码我看其他地方也有些的。难道前面的没有问题??

  • 策略一:
    • 立马debug 试了一下以前的代码,发现 都没有进入,一直没有调用。

  • 策略二: google

  • 反思:

    • 看到 异常信息,并且 类的权限定名都一样,应该要 想到 肯能是 classLoader 的问题了,这是基础,但 在实际中 却不能很好的应用 知识。

  • 花了我好久的时间来排查这个问题,真是太 low b了。

原文地址:https://www.cnblogs.com/idea-persistence/p/13386705.html