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.MaxUploadSizeExceededException
22:40:28,574 WARN http-apr-8080-exec-5 commons.CommonsMultipartResolver:194 - Failed to perform multipart cleanup for servlet request
org.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)注解的方法中打印的,我也在这个方法中作了响应处理,但是客户端访问的时候就会显示无响应,不知道是什么鬼,求大神解答!!!!
翻过高山走不出你
四季花海
紫衣仙女
相关分类