【spring-boot脱坑指南】增强for循环遍历同类型时报错 java.lang.ClassCastException

5 篇文章 0 订阅
4 篇文章 0 订阅
	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:

  1. Disable cache when you’re running your application in development
  2. 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)
  3. 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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值