Error message:
The field file exceeds its maximum permitted size of 1048576 bytes
the reason:
The reason is that the file size that SpringBoot embedded tomcat can upload by default is 1M, and an error will be reported if it exceeds this.
solution:
1. Modify the default configuration of springboot in the configuration file
spring: http: multipart: enabled: true max -file- size: 30MB max -request-size: 30MB
Two, write the configuration class
package com.blog.springboot.config; import javax.servlet.MultipartConfigElement; import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class MulterFile { /** * File upload configuration * @return */ @Bean public MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); // Maximum file size factory.setMaxFileSize("30960KB"); // KB,MB // / Set the total upload data size factory.setMaxRequestSize("309600KB" ); return factory.createMultipartConfig() ; } }
The above two solutions have advantages and disadvantages. The first is more concise and convenient without using redundant code. In the second case, although more code needs to be written and a configuration file needs to be added, it is better to put this configuration information on the bright side, because this is beneficial to the later maintenance, and this configuration Under normal circumstances, there are very few changes, basically the configuration is ok once. Reduce the redundant information in the yml file. Especially for the springcloud project.
Similar Posts:
- Cannot resolve reference to bean ‘entityManagerFactory’ while setting constructor argument
- Springboot starts with @ scheduled and reports an error: no qualifying bean
- [Solved] org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
- [Solved] NoSuchMethodError: org.springframework.boot.web.servlet.error.ErrorController.getErrorPath
- [Solved] SpringbootExpection 1: Error creating bean with name ‘xxxImpl’: Unsatisfied dependency expressed through field
- Two ways to implement Spring Boot’s scanmapper interface class
- [Solved] Import AOP Error: error at ::0 formal unbound in pointcut
- [Solved] Dependency injection exception: org.springframework.beans.factory.UnsatisfiedDependencyException
- [Solved] Redisson Error: Caused by: java.lang.IllegalArgumentException: RIVER
- [Solved] No qualifying bean of type ‘org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder’ available: