Background: Spring boot project, add goods and goods price list
Goods:
List<GoodsPrice> pricelist;
in controller first convert goodsForm to goods(by dozer), then save goods,after saving goods iterate goods price list to populate goodsId.
goods.getPriceList().forEach(p -> p.setGoodsId(goods.getId()));
When iterate goods price list, throw exception:
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]
Somebody remind me this exception related to classloader, and in eclipse debug mode, I outputed the GoodsPrice's ClassLoader:
sun.misc.Launcher$AppClassLoader@14dad5dc
and goods:
org.springframework.boot.devtools.restart.classloader.RestartClassLoader@591c6338
Indeed exist diff classloader.
Then I commented spring-boot-devtools
then tried again this time it's ok.
So if still retain spring-boot-devtools
, how to solve this problem?