問題描述:
過濾器中,解析請求體後,進入Controller後,報異常:Resolved [org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is java.io.IOException: Stream closed],
原因:
從HttpServletRequest中獲取到InputStream後,就不能再次獲取請求體
解決方法:
參考鏈接:https://blog.csdn.net/lanxing_huangyao/article/details/86687851
或者參考:com.mzqh.filter.TokenFilter
思路:
1、繼承 HttpServletRequestWrapper自定義請求Wrapper
2、解析請求體,同時其設置到流 ServletInputStream 中
3、過濾器中 方法 doFilter 中的request設置爲 HttpServletRequestWrapper 繼續傳遞流即可