【JAVA】org.springframework.beans.FatalBeanException: Could not copy property 'beginInventory' from source to target


異常報錯如下:

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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM