我们正在切换到JavaConfig,我们在让多部分上传工作时遇到问题
org.springframework.web.multipart.MultipartException: The current request is not a multipart request
我们的配置仍然使用security.xml,我尝试了一些建议
MultipartResolver and AbstractAnnotationConfigDispatcherServletInitializer
How to nicely handle file upload MaxUploadSizeExceededException with Spring Security
但是,它不起作用。
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"nl.project.controller"},includeFilters={
@ComponentScan.Filter(type=FilterType.ANNOTATION,value=Controller.class),
@ComponentScan.Filter(type=FilterType.ANNOTATION,value=RestController.class)
})
public class ServletConfig extends WebMvcConfigurerAdapter{
@Bean
public CommonsMultipartResolver filterMultipartResolver(){
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setMaxUploadSize(5000000);
resolver.setMaxInMemorySize(10000);
resolver.setDefaultEncoding("utf-8");
return resolver;
}
任何建议都会非常感谢!
答案 0 :(得分:0)
如果您发布了安全配置和完整的堆栈跟踪,那么回答会更容易。
但是,我猜你正在遇到CSRF保护问题。您需要阅读参考文献的CSRF - Multipart (file upload)部分。
如果这没有帮助,请发布完整的堆栈跟踪和安全配置。