異常報錯如下:
2020-06-23 09:52:13.674 [http-nio-8009-exec-1] [6e97d911bd4d97a5] [6e97d911bd4d97a5] [ERROR] org.springframework.beans.BeanUtils:Could not copy property 'beginInventory' from source to target; nested exception is java.lang.IllegalArgumentException org.springframework.beans.FatalBeanException: Could not copy property 'beginInventory' from source to target; nested exception is java.lang.IllegalArgumentException at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:625) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE] at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:537)
出現該異常的代碼行如下:
BeanUtils.copyProperties(src, dest);
經過排查原因如下:
src的POJO類中字段定義如下:
private Integer beginInventory;
dest的POJO類中字段定義如下:
private int beginInventory;
由於src的beginInventory值為null,導致無法賦值給dest中的int類型,所以報錯
解決方法是,將src中的Integer類型字段賦予一個初始值(比如0)