title: A dozer map exception related to Spring boot devtools
body: <p>I have encountered a very strange exception, and I don't know how to find the reason.</p>
  
  <p>Business background:
  Add goods and meantime it's price list, a goods have 5 price for diff level user.</p>
  
  <p>In controller, first convert goodForm to goods by using dozer, then call goodsService to save goods.
  In goodsService after saving goods, traversal goods price list and populate goodsId to goods price, </p>
  
  <pre><code>GoodsForm:
  @Mapping("priceList")
  List&lt;GoodsPriceForm&gt; goodsPriceFormList;
  Goods:
  List&lt;GoodsPrice&gt; priceList;
  
  Controller: 
  Goods goods = BeanMapper.map(goodsForm, Goods.class);
  goodsService.saveGoods(adminId, goods);
  
  GoodsService:
  goodsDao.save(goods);
  goods.getPriceList().forEach(p -&gt; p.setGoodsId(goods.getId()));
  goodsPriceDao.save(goods.getPriceList());
  </code></pre>
  
  <p>But it throw exception:</p>
  
  <pre><code>2015-11-27 17:10:57,042 [http-nio-8081-exec-8] ERROR o.a.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: com.foo.goods.model.GoodsPrice cannot be cast to com.foo.goods.model.GoodsPrice] with root cause
  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]
  </code></pre>
  
  <p>This error message let me feel very confused.  In addition I write a unit test wanted to repeat this, but failed.</p>
  
  <pre><code>GoodsForm form = new GoodsForm();
  form.setGoodsPriceFormList(Lists.newArrayList(new GoodsPriceForm((byte) 1, BigDecimal.valueOf(10)),
  new GoodsPriceForm((byte) 2, BigDecimal.valueOf(9)),
  new GoodsPriceForm((byte) 3, BigDecimal.valueOf(8))));
  
  Goods goods = BeanMapper.map(form, Goods.class);
  goods.getPriceList().forEach(p -&gt; p.setGoodsId(goods.getId()));
  </code></pre>
  
  <p>Run this unit test, it executed ok. 
  So why in real web situation(Spring boot + Jpa) it's failed, but in unit test situation it's ok?</p>
  
  <hr>
  
  <pre><code>Controller:
  System.out.println("PriceList: " + goods.getPriceList().getClass().getClassLoader());//PriceList: null
  System.out.println(goods.getPriceList().get(0).getClass().getClassLoader()); //java.lang.ClassCastException: com.foo.goods.model.GoodsPrice cannot be cast to com.foo.goods.model.GoodsPrice
  </code></pre>
  
  <hr>
  
  <p>If I generated a packaged jar, then execute this jar</p>
  
  <pre><code>java -jar target/myapp.jar
  </code></pre>
  
  <p>In this case without above exception.</p>
  
  <hr>
  
  <p>And I commented spring-boot-devtools in pom.xml, then started application, without above exception.</p>