报错提示:
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'roleId' cannot be found on null
错误发生在删除角色时,原因是删除角色的方法上写了@CacheEvict(key = "#role.roleId")
一般情况下.@CacheEvict 在方法执行完之后执行,在我的场景里,把role删了,再清除role.roleId的缓存,方法执行完之后显然role==null了,找不到roleId
解决方法:
@CacheEvict(key = "#roleId")
或者
@CacheEvict(key = "#role.roleId",beforeInvocation = true)
使得清除缓存的操作在方法执行之前进行