org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jboss.resteasy.plug

之前做的项目是resteasy的上传,代码没有问题,断点都不进来呢。

我以为可以直接移植到SpringMVC,但是SpringMVC不支持MultipartFormDataInput

用MultipartFile就可以了。老的无法兼容新的。正确代码如下

 
 
@RequestMapping(value = "/importExcelForEduQuestion",produces = "application/json; charset=utf-8")
@ResponseBody
//@RequiresPermissions("eduQuestionBank:importExcelForEduQuestion")
public Map<String,Object> importExcelForEduQuestion(HttpServletRequest request, @RequestParam("excelPath") MultipartFile file){
//如果文件不为空,写入上传路径
if(!file.isEmpty()) {
//上传文件路径
//上传文件名
String filename = file.getOriginalFilename();
File filepath = new File(UPLOADED_FILE_PATH,filename);
//判断路径是否存在,如果不存在就创建一个
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
//将上传文件保存到一个目标文件当中
try {
file.transferTo(new File(UPLOADED_FILE_PATH + File.separator + filename));
} catch (IOException e) {
e.printStackTrace();
}
return ResultUtil.createSuccessResult();
} else {
return ResultUtil.createFailResult("上传失败");
}
}
 

猜你喜欢

转载自www.cnblogs.com/Java-Starter/p/9139460.html