Spring Boot multipartfile always null

前端 未结 5 1779
悲&欢浪女
悲&欢浪女 2021-02-04 10:02

I am using Spring Boot version = \'1.4.0.RC1\' with Spring Boot Stormpath 1.0.2.

I am trying to use multipart file upload but the MultipartFile is always null in the con

5条回答
  •  悲哀的现实
    2021-02-04 10:34

    You have to enable the Spring Multipart Resolver as by default Spring doesn't enable the multipart capability.

    By default, Spring does no multipart handling, because some developers want to handle multiparts themselves. You enable Spring multipart handling by adding a multipart resolver to the web application’s context.

    To your configuration class you would want to add the following bean:

    @Bean
    public MultipartResolver multipartResolver() {
        return new StandardServletMultipartResolver();
    }
    

    Since spring boot 1.4+ uses servlet 3.0+ we can leverage on StandardServletMultipartResolver instead of classic CommonsMultipartResolver

提交回复
热议问题