springmvc上传文件报错org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.multipart.MultipartFile]
在用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]的更多相关文章
- Spring MVC实现上传文件报错解决方案
报错代码: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.sp ...
- Linux - xshell上传文件报错乱码
xshell上传文件报错乱码,解决方法 rz -be 回车 下载sz filename
- Azkban上传文件报错installation Failed.Error chunking
azkaban 上传文件报错Caused by: java.sql.SQLException: The size of BLOB/TEXT data inserted in one transacti ...
- Tomcat上传文件报错:returned a response status of 403 Forbidden
出现这样的错误是没有权限对服务器进行写操作.需要在这个项目所在的tomcat中配置可写操作即可: 在tomcat的web.xml添加下面代码: <init-param><param- ...
- 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 ...
- 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 ...
- 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 ...
- Spring使用mutipartFile上传文件报错【Failed to instantiate [org.springframework.web.multipart.MultipartFile]】
报错场景: 使用SSM框架实现文件上传时报“Failed to instantiate [org.springframework.web.multipart.MultipartFile]”错,控制器源 ...
- SecureCRT sftp上传文件报错:put: failed to upload xxx 拒绝访问
1.问题 使用sftp上传文件时报错:put: failed to upload xxx 拒绝访问.类似下图所示: 2.原因 造成这个问题的原因可能有两个,一是要上到的那个目录剩余磁盘空间不足,二是打 ...
随机推荐
- django-groundwork
我的环境是windows7 + python34 + django1.8 下面两篇文章提到了django的scaffold,感觉是一个挺不错的功能: Django实战(3):Django也可以有sca ...
- 函数内联inline
C++语言支持函数内联,其目的是为了提高函数的执行效率(速度). 宏的优点 在C程序中,可以用宏代码提高执行效率. 编译预处理器用拷贝宏代码的方式取代函数调用,省去了参数压栈,生成汇编语言的CALL调 ...
- nginx反向代理解决wechat图片问题
在nginx 中nginx.conf开启反向代理 location ^~ /wechat_image/ { add_header 'Access-Control-Allow-Origin' " ...
- P4774 [NOI2018]屠龙勇士
P4774 [NOI2018]屠龙勇士 先平衡树跑出打每条龙的atk t[] 然后每条龙有\(xt \equiv a[i](\text{mod }p[i])\) 就是\(xt+kp[i]=a[i]\) ...
- ubuntu下编译源码 make 出现 make: 'Makefile' is up to date.
其实只需要 make就行了,不需要 make Makefile 当然,make的前提是,执行 ./configure 不报错
- 【ASP.NET Core】运行原理(1):创建WebHost
本系列将分析ASP.NET Core运行原理 [ASP.NET Core]运行原理[1]:创建WebHost [ASP.NET Core]运行原理[2]:启动WebHost [ASP.NET Core ...
- Python 10min系列之面试题解析丨Python实现tail -f功能
关于这道题,简单说一下我的想法吧.当然,也有很好用的 pyinotify 模块专门监听文件变化,不过我更想介绍的,是解决的思路. 毕竟作为面试官,还是想看到一下解决问题的思路,而且我觉得这一题的难点不 ...
- Web开发框架趋势
Node.js增长很快,已经冒尖了 ASP.NET MVC 发展平稳(平稳很重要) Spring MVC沾着Spring的光,渐渐超越了Struts 2 Struts作为一个整体(Struts 1 和 ...
- vue使用import来引入组件的注意事项
Vue使用import ... from ...来导入组件,库,变量等.而from后的来源可以是js,vue,json.这个是在webpack.base.conf.js中设置的: module.exp ...
- Python中的注释
1.1 注释的目的 通过用自己熟悉的语言,在程序中对某些代码进行标注说明,这就是注释的作用,能够大大增强程序的可读性. 1.2 注释的分类 1.2.1 单行注释 以#开头,#右边的所有东西当做说明,而 ...