<form:form action="/casacode/produtos" method="POST"
commandName="produto" enctype="multipart/form-data">
//Produto controle
@RequestMapping(method = RequestMethod.POST)
public ModelAndView grava(MultipartFile sumario , @Valid Produto produto,BindingResult result,RedirectAttributes red) {
System.out.println(produto);
System.out.println(sumario.getOriginalFilename());
if(result.hasErrors()) {
return from(produto);
}
produtodao.gravar(produto);
red.addFlashAttribute("sucesso", "produto cadastrado com sucesso");
return new ModelAndView("redirect:produtos");
}
//Appwebconfiguração
@Bean
public MultipartResolver multipartResolver() {
return new StandardServletMultipartResolver();
}
//servilet_mvc
@Override
protected void customizeRegistration(Dynamic registration) {
registration.setMultipartConfig(new MultipartConfigElement(""));
}
Erro apresentado é
set. 12, 2020 9:05:52 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/casacode] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: The current request is not a multipart request] with root cause
org.springframework.web.multipart.MultipartException: The current request is not a multipart request
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.assertIsMultipartRequest(RequestParamMethodArgumentResolver.java:218)
at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.resolveName(RequestParamMethodArgumentResolver.java:170)
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:89)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:79)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:157)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:124)