在用springmvc+mybatis进行项目开发时,上传文件抛异常...

org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.multipart.MultipartFile]: Specified class is an interface
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:101)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:762)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:356)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

解决方法:在Controller的MultipartFile参数前面加上@RequestParam就行了!

如:

@RequestMapping("/save")
public String save(User user,
HttpServletResponse response,
@RequestParam MultipartFile file_pic//接收图片
)throws Exception{ //原始名称
String originalFilename = file_pic.getOriginalFilename();
//上传图片
if(file_pic!=null && originalFilename!=null && originalFilename.length()>0){
//存储图片的物理路径
String pic_path = "G:\\nfsysuems\\temp\\";
//新的图片名称
String newFileName = UUID.randomUUID() + originalFilename.substring(originalFilename.lastIndexOf("."));
//新图片
File newFile = new File(pic_path+newFileName);
//将内存中的数据写入磁盘
file_pic.transferTo(newFile);
//新图片写入user
user.setPic(newFileName);
}
.......

springmvc上传文件报错org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.multipart.MultipartFile]的更多相关文章

  1. Spring MVC实现上传文件报错解决方案

    报错代码: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.sp ...

  2. Linux - xshell上传文件报错乱码

    xshell上传文件报错乱码,解决方法 rz -be 回车 下载sz  filename

  3. Azkban上传文件报错installation Failed.Error chunking

    azkaban 上传文件报错Caused by: java.sql.SQLException: The size of BLOB/TEXT data inserted in one transacti ...

  4. Tomcat上传文件报错:returned a response status of 403 Forbidden

    出现这样的错误是没有权限对服务器进行写操作.需要在这个项目所在的tomcat中配置可写操作即可: 在tomcat的web.xml添加下面代码: <init-param><param- ...

  5. rz上传文件报错:rpm Read Signature failed: sigh blob(1268): BAD, read returned 0

    上传文件报错: [root@www localdisk]# rpm -ivh cobbler* error: cobbler-2.8.4-4.el7.x86_64.rpm: rpm  Read  Si ...

  6. org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class

    错误:org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util ...

  7. org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.hs.model.StudentModel]: No default constructor found; nested exception is java.lang.NoSuchMethodException: c

    root cause org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [c ...

  8. Spring使用mutipartFile上传文件报错【Failed to instantiate [org.springframework.web.multipart.MultipartFile]】

    报错场景: 使用SSM框架实现文件上传时报“Failed to instantiate [org.springframework.web.multipart.MultipartFile]”错,控制器源 ...

  9. SecureCRT sftp上传文件报错:put: failed to upload xxx 拒绝访问

    1.问题 使用sftp上传文件时报错:put: failed to upload xxx 拒绝访问.类似下图所示: 2.原因 造成这个问题的原因可能有两个,一是要上到的那个目录剩余磁盘空间不足,二是打 ...

随机推荐

  1. Kubernetes学习之路(三)之Mater节点二进制部署

    K8S Mater节点部署 1.部署Kubernetes API服务部署 apiserver提供集群管理的REST API接口,包括认证授权.数据校验以及集群状态变更等. 只有API Server才能 ...

  2. 一个java程序员该具备的工具

    http://itindex.net/detail/37115-java-%E7%A8%8B%E5%BA%8F%E5%91%98-%E5%B7%A5%E5%85%B7 文章很详细.

  3. redis基本使用

    一 简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted ...

  4. Qt-网易云音乐界面实现-5 收藏列表,播放列表实现 QListWidget QTableWidget

    先上目前完成的内容吧,发现后面越写越多.在看看点击量,心凉凉. 完成了左侧的导航列表,还有就是右下角的播放列表. //创建的歌单 my_Create_Music_List = new QListWid ...

  5. (2017)你最不建议使用的Python Web框架?

    https://www.sohu.com/a/164042813_737973   挺有意思的 经过一周的Django学习,以及对比,最终选定了以Flask入手来学习Python web开发.

  6. mac zsh不自动加载~/.bashrc

    修改了bashrc, 新开一个终端都要source一下才起作用. 网上有说需要在 . bash_profile加载一次.bashrc. 但是这个和我的问题不一样. 我用的是zsh,需要修改~/.zsh ...

  7. 4星|《钱的历史》:大英博物馆的钱币简史,彩图众多不适合在kindle上阅读

    钱的历史(大英博物馆权威出品,一部金钱简史) 大英博物馆的两位钱币馆馆长的作品.非常专业.基本是世界钱币简史.从钱币的发展变迁讲到涉及到的历史大事,重心当然是欧洲的钱币史,中国.印度也各安排了一章. ...

  8. 学习python,第一篇

    name = "danie" name2 = name print(name,name2) name = "itxpl" print(name,name2) 结 ...

  9. 推荐3个小程序开源组件库——Vant、iView、ColorUI

    推荐3个小程序开源组件库 在进行小程序开发时,经常会遇到编写组件方面的阻碍,这让我们花费大量的时间在页面以及 CSS 样式编写上.因此可以使用开源组件库,有些复杂的组件可以直接拿来使用,节省开发时间, ...

  10. Webrtc源码走读(一)

    阅读event_wrapper.h   event_wrapper_win.cpp 的实现 自己对“事件”这个词没有深的理解,通过看段代码,好像有点感觉,类似与C#的AutoResetEvent