private Set<QaSysUserDto.UserRights> getRightsByGroups(Set<QaSysUserGroupDto> qaSysUserGroup) {
//遍历角色,把拥有的权限集中起来
for(QaSysUserGroupDto userGroup : qaSysUserGroup) { // 此处报错ClassCastException
}
}
原因:spring-boot 热部署造成的
解决方法:注释 devtool 依赖
<!-- 热部署 增强for循环时报错,同类型不能转换 java.lang.ClassCastException -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>runtime</scope>
</dependency> -->
其他解决方法(来源stackoverflow):
This is a known limitation of Devtools. When the cache entry is deserialized, the object is not attached to the proper classloader.
There are various ways you can fix this issue:
- Disable cache when you’re running your application in development
- Use a different cache manager (if you’re using Spring Boot 1.3, you could force a simple cache manager using the spring.cache.type property in application-dev.properties and enable the dev profile in your IDE)
- Configure memcached (and things that are cached) to run in the application classloader. I wouldn’t recommend that option since the two first above are much easier to implement