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
提交
取消