springboot上传附件报错Failed to convert value of type

  • 上传附件报错Failed to convert value of type ‘org.springframework.web.multipart.support.StandardMultipartHttpServletRequest S t a n d a r d M u l t i p a r t F i l e ′ t o r e q u i r e d t y p e ′ o r g . s p r i n g f r a m e w o r k . w e b . m u l t i p a r t . c o m m o n s . C o m m o n s M u l t i p a r t F i l e ′ ; n e s t e d e x c e p t i o n i s j a v a . l a n g . I l l e g a l S t a t e E x c e p t i o n : C a n n o t c o n v e r t v a l u e o f t y p e ′ o r g . s p r i n g f r a m e w o r k . w e b . m u l t i p a r t . s u p p o r t . S t a n d a r d M u l t i p a r t H t t p S e r v l e t R e q u e s t StandardMultipartFile' to required type 'org.springframework.web.multipart.commons.CommonsMultipartFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.springframework.web.multipart.support.StandardMultipartHttpServletRequest StandardMultipartFiletorequiredtypeorg.springframework.web.multipart.commons.CommonsMultipartFile;nestedexceptionisjava.lang.IllegalStateException:Cannotconvertvalueoftypeorg.springframework.web.multipart.support.StandardMultipartHttpServletRequestStandardMultipartFile’ to required type ‘org.springframework.web.multipart.commons.CommonsMultipartFile’: no matching editors or conversion strategy found
  • 完整报错如下

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sat Apr 13 15:38:27 CST 2019
There was an unexpected error (type=Internal Server Error, status=500).
Failed to convert value of type ‘org.springframework.web.multipart.support.StandardMultipartHttpServletRequest S t a n d a r d M u l t i p a r t F i l e ′ t o r e q u i r e d t y p e ′ o r g . s p r i n g f r a m e w o r k . w e b . m u l t i p a r t . c o m m o n s . C o m m o n s M u l t i p a r t F i l e ′ ; n e s t e d e x c e p t i o n i s j a v a . l a n g . I l l e g a l S t a t e E x c e p t i o n : C a n n o t c o n v e r t v a l u e o f t y p e ′ o r g . s p r i n g f r a m e w o r k . w e b . m u l t i p a r t . s u p p o r t . S t a n d a r d M u l t i p a r t H t t p S e r v l e t R e q u e s t StandardMultipartFile' to required type 'org.springframework.web.multipart.commons.CommonsMultipartFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.springframework.web.multipart.support.StandardMultipartHttpServletRequest StandardMultipartFiletorequiredtypeorg.springframework.web.multipart.commons.CommonsMultipartFile;nestedexceptionisjava.lang.IllegalStateException:Cannotconvertvalueoftypeorg.springframework.web.multipart.support.StandardMultipartHttpServletRequestStandardMultipartFile’ to required type ‘org.springframework.web.multipart.commons.CommonsMultipartFile’: no matching editors or conversion strategy found
org.springframework.web.method.annotation.MethodArgumentConversionNotSupportedException: Failed to convert value of type ‘org.springframework.web.multipart.support.StandardMultipartHttpServletRequest S t a n d a r d M u l t i p a r t F i l e ′ t o r e q u i r e d t y p e ′ o r g . s p r i n g f r a m e w o r k . w e b . m u l t i p a r t . c o m m o n s . C o m m o n s M u l t i p a r t F i l e ′ ; n e s t e d e x c e p t i o n i s j a v a . l a n g . I l l e g a l S t a t e E x c e p t i o n : C a n n o t c o n v e r t v a l u e o f t y p e ′ o r g . s p r i n g f r a m e w o r k . w e b . m u l t i p a r t . s u p p o r t . S t a n d a r d M u l t i p a r t H t t p S e r v l e t R e q u e s t StandardMultipartFile' to required type 'org.springframework.web.multipart.commons.CommonsMultipartFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'org.springframework.web.multipart.support.StandardMultipartHttpServletRequest StandardMultipartFiletorequiredtypeorg.springframework.web.multipart.commons.CommonsMultipartFile;nestedexceptionisjava.lang.IllegalStateException:Cannotconvertvalueoftypeorg.springframework.web.multipart.support.StandardMultipartHttpServletRequestStandardMultipartFile’ to required type ‘org.springframework.web.multipart.commons.CommonsMultipartFile’: no matching editors or conversion strategy found
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:128)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:126)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:166)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol C o n n e c t i o n H a n d l e r . p r o c e s s ( A b s t r a c t P r o t o c o l . j a v a : 834 ) a t o r g . a p a c h e . t o m c a t . u t i l . n e t . N i o E n d p o i n t ConnectionHandler.process(AbstractProtocol.java:834) at org.apache.tomcat.util.net.NioEndpoint ConnectionHandler.process(AbstractProtocol.java:834)atorg.apache.tomcat.util.net.NioEndpointSocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor W o r k e r . r u n ( T h r e a d P o o l E x e c u t o r . j a v a : 624 ) a t o r g . a p a c h e . t o m c a t . u t i l . t h r e a d s . T a s k T h r e a d Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread Worker.run(ThreadPoolExecutor.java:624)atorg.apache.tomcat.util.threads.TaskThreadWrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Cannot convert value of type ‘org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile’ to required type ‘org.springframework.web.multipart.commons.CommonsMultipartFile’: no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:262)
at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:73)
at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:53)
at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:693)
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:124)
… 51 more

网上找了很多资料也没找到解决方法,最后凑巧解决了

- 原因如下:
 接收上传的附件时使用了CommonsMultipartFile类,应该换成MultipartFile类,就解决了上传附件出错的问题.

大家可以扫一扫关注下我的公众号哟
springboot上传附件报错Failed to convert value of type_第1张图片

你可能感兴趣的:(SpringBoot,java)