与spring-boot-devtools相关的类加载器问题 [英] A classloader proplem related to spring-boot-devtools

查看:298
本文介绍了与spring-boot-devtools相关的类加载器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:
春季启动项目,添加商品和商品价格清单

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]

有人提醒我这个与类加载器有关的异常,在日食调试模式下,我输出了GoodsPrice的ClassLoader:

Somebody remind me this exception related to classloader, and in eclipse debug mode, I outputed the GoodsPrice's ClassLoader:

sun.misc.Launcher$AppClassLoader@14dad5dc

和商品:
org.springframework.boot.devtools.restart.classloader.RestartClassLoader@591c6338

确实存在差异类加载器。
然后我评论了 spring-boot-devtools ,然后再次尝试就可以了。
那么,如果仍然保留 spring-boot-devtools ,该如何解决呢?

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?

推荐答案

推土机使用了错误的类加载器。

您可以解决该问题,并将此文件添加到资源文件夹中:

META-INF / spring-devtools.properties

,内部:


restart.include.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

Dozer is using the wrong classloader.
You can solve it adding this file in your resource folder :
META-INF/spring-devtools.properties
with inside :
restart.include.dozer=/dozer-5.5.1.jar
restart.include.dozer-spring=/dozer-spring-5.5.1.jar (only if you use this jar!)
sources : http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-devtools-customizing-classload

这篇关于与spring-boot-devtools相关的类加载器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆