spring mvc上傳文件超過設定大小異常處理客戶端無響應;controller類 @RequestMapping(path = "/file", method = RequestMethod.POST) public UploadMsg uploadFile(@RequestParam("uploadFile") MultipartFile file, String userCode) throws Exception { String fileId = genFileId(); saveFileToSystem(file, fileId); UploadMsg uploadMsg = getUploadMsg(userCode, fileId, file.getSize()); return uploadMsg; } @ExceptionHandler(MaxUploadSizeExceededException.class) public ResponseEntity<String> handleException(MaxUploadSizeExceededException ex) { System.out.println("=====================" + ex.getClass().getName()); return ResponseEntity.ok("ok"); }spring配置文件配置文件大小不能超過1M <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="UTF-8"/> <property name="maxUploadSize" value="#{1*1024*1024}"/> <property name="resolveLazily" value="true"/> </bean>下面是我用小于1M的文件訪問時的情況這是上傳失敗的情況下面是我的日志打印情況22:40:28,569 DEBUG http-apr-8080-exec-5 support.DefaultListableBeanFactory:251 - Returning cached instance of singleton bean 'uploadFileController'=====================org.springframework.web.multipart.MaxUploadSizeExceededException22:40:28,574 WARN http-apr-8080-exec-5 commons.CommonsMultipartResolver:194 - Failed to perform multipart cleanup for servlet requestorg.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size of 1048576 bytes exceeded; nested exception is org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (6145455) exceeds the configured maximum (1048576) 這句是我在@ExceptionHandler(MaxUploadSizeExceededException.class)注解的方法中打印的,我也在這個方法中作了響應處理,但是客戶端訪問的時候就會顯示無響應,不知道是什么鬼,求大神解答?。。。?
3 回答

翻過高山走不出你
TA貢獻1875條經驗 獲得超3個贊
從這里找到了答案關于spring mvc MaxUploadSizeExceededException 死循環解決方
據說是tomcat的bug,我試了下用jetty運行,果然是沒有問題的,至于低版本的tomcat還沒測試。

四季花海
TA貢獻1811條經驗 獲得超5個贊
@ExceptionHandler(MaxUploadSizeExceededException.class)
@ResponseBody
public ResponseEntity<String> handleException(MaxUploadSizeExceededException ex) {
System.out.println("=====================" + ex.getClass().getName());
return ResponseEntity.ok("ok");
}
看看是不是少了個@ResponseBody。

紫衣仙女
TA貢獻1839條經驗 獲得超15個贊
weblogic也有這個問題,圖片上傳超時了,客戶端status還是pending,沒有響應,已經寫了@ExceptionHandler和@ResponseBody,返回一個map對象,但是客戶端沒有響應,懷疑weblogic沒做響應處理
添加回答
舉報
0/150
提交
取消