“有悖常理” bug的場景

serviceImpl 中@min 不生效

解決方案: serviceImpl 加 @Validated,service接口對應方法加@min。
解決問題的過程出現其他情況:

  1. serviceImpl 方法加 @min 同時 service 中方法不加@min 報錯

,大致意思是實現類和接口不一致 。詳細: javax.validation.ConstraintDeclarationException: HV000151: A method overriding another method must not redefine the parameter constraint configuration, but method XxxServiceImpl#delete(int) redefines the configuration of XxxService#delete(int)。
解決方案 XxxServiceImpl#delete(int) 不加@min 同時XxxServiceImpl#delete(int) 不加@min,解決了 。但是@Validated在 實現類 @min在接口 四不像的樣子。

restTemplate 不能解將返回的json 解析爲 javabean 報錯如下

org.springframework.web.client.RestClientException: Error while extracting response for type [class xxx.xxx.OrderResponse] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of xx.xxx.xxx.OrderResponse$Order (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of xxx.xxx.dto.OrderResponse$Order (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor
at [Source: (PushbackInputStream); line: 1, column: 33] (through reference chain: xxx.xxx.xxx.dto.OrderResponse[“data”]->xxx.xxx.xxx.dto.OrderResponse$Data[“content”]->java.util.ArrayList[0])

原因分析 :

字面意思 :沒法轉換 爲 對應的xxx.xxx.xxx.dto.OrderResponse$Data[“content”]。
環境
我這裏的content 是一個 list<自定義對象A> 看json串 嵌套層級啥的 確定對應關係沒問題的。再仔細看上邊的 提示(自己藍色處)can only instantiate non-static inner class by using default, no-argument constructor 個人理解 : :“只能使用默認的無參數構造函數實例化非靜態內部類”。 我自己的這個類確實是內部類,內部類有啥問題嗎?然後就沒關心。
沒頭緒了 準備自己生成一個json 對比下 是不是json層級問題 ,當寫到 new OrderResponse.自定義對象A() 標紅了 ,啥情況???,我靠 原來 內部類不能直接new 內部類必須加static 關鍵字 才能new 。 加了static後 restTemplate也可以解析了,完結。

Target host is not specified

場景 : 使用spring boot 單元測試時 報了這個錯。
原因 :原因路徑的口頭沒有 / 。可用url “/XXX/XXX”,報錯url “XXX/XXX”。這裏有個大坑 最上層的報錯是 org.springframework.web.client.ResourceAccessException: I/O error on POST request for “/XXX/XXX”: null; nested exception is org.apache.http.client.ClientProtocolException。讓人以爲 resttemplate會自動加前邊的“”/“”。就不會想到是 url前邊不加“”/“”導致才報host 沒發現。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章