一个与Spring-Boot-DevTools相关的类加载器问题 [英] A classloader problem related to spring-boot-devtools
本文介绍了一个与Spring-Boot-DevTools相关的类加载器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
背景: Spring Boot项目,添加商品和商品价目表
Goods:
List<GoodsPrice> pricelist;
在控制器中,先将Goods Form转换为Goods(通过推土机),然后保存商品,保存商品后,迭代商品价目表以填充GoodsID。
goods.getPriceList().forEach(p -> p.setGoodsId(goods.getId()));
迭代商品价目表时抛出异常:
java.lang.ClassCastException: com.foo.goods.model.GoodsPrice cannot be cast to com.foo.goods.model.GoodsPrice
at com.foo.goods.service.GoodsService$$Lambda$11/310447431.accept(Unknown Source) ~[na:na]
at java.util.ArrayList.forEach(ArrayList.java:1249) ~[na:1.8.0_51]
at com.foo.goods.service.GoodsService.saveGoods(GoodsService.java:34) ~[classes/:na]
有人提醒我这个异常与类加载器相关,在eclipse调试模式下,我输出了GoodsPrice的ClassLoader:
sun.misc.Launcher$AppClassLoader@14dad5dc
和货物:
org.springframework.boot.devtools.restart.classloader.RestartClassLoader@591c6338
spring-boot-devtools
,然后再试了一次,这次没问题。
那么如果仍然保留spring-boot-devtools
,如何解决这个问题呢?
推荐答案
推土机使用了错误的类加载器。
您可以解决在您的资源文件夹中添加此文件的问题:
META-INF/Spring-devtools.properties
带内装:
Restart.cludde.dozer=/dozer-5.5.1.jar
Restart.include.dozer-spring=/dozer-spring-5.5.1.jar(只有在您使用这个JAR的情况下!)
来源:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-devtools-customizing-classload
这篇关于一个与Spring-Boot-DevTools相关的类加载器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文