javax.validation.UnexpectedTypeException: HV00030: No validator could be found for constraint 'org.hibernate.constraint.Length' validating type 'java.time.LocalDateTime' . Check configuration for 'inTime'java
1.先說明一下該bug的由來,一個微服務A去調用另外一個微服務B,微服務B出現了上面的異常日誌,而微服務A的異常日誌以下,feign.FeignException:status 500 reading xxxhandlexx(String,xxDTO):
2.因爲被調用的B微服務已經有了異常日誌,說明該調用已經發送到B微服務了,咱們能夠從B微服務的異常日誌來排查異常。
3.回到第一張圖的異常日誌,這裏已經很清晰了,javax.validation.UnexpectedTypeException: HV00030: No validator could be found for constraint 'org.hibernate.constraint.Length' validating type 'java.time.LocalDateTime' . Check configuration for 'inTime',validation參數校驗的時候出現了異常,LocalDateTime類型的變量inTime沒法找到有Length的校驗約束,請檢查'inTime'變量的配置,這裏的inTime是方法參數DTO對象的一個字段,如圖所示:
這裏的@Length(max = 30)是致使異常的主要緣由,筆者起初inTime的變量類型是String類型,上面加了@Length(max = 30)參數校驗,後來換成了LocalDateTime,可是當時也不知道不能用@Length(max = 30)參數校驗也忘記去掉了,這裏致使方法入參的時候校驗失敗,拋出異常。那麼爲何@Length註解沒法用到LocalDateTime變量類型上呢?咱們點進去看一下源碼:
註釋:Validate that the string is between min and max included.能夠看到只是能用於註解到String類型的變量。把@Length去掉bug就解決了。微服務