springBoot上传⽂件⼤⼩设置
框架架构: springboot+hibernate+freemarker+ueditor, tomcat内嵌在springboot⾥⾯,由于是内嵌,⽤ueditor上传图⽚,tomcat默认上传为1M,所以上传⼤图⽚就会报错。
报错为:
nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: at.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field upfile exceeds its maximum permitted size of 1048576 bytes.] with root cause
at.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field upfile exceeds its maximum permitted size of 1048576 bytes.
at at.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:633)
spring framework是什么框架的at at.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76)
at at.util.http.fileupload.ad(LimitedInputStream.java:135)
at java.ad(FilterInputStream.java:107)
at at.util.http.fileupload.py(Streams.java:98)
at at.util.http.fileupload.py(Streams.java:68)
at at.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:293)
at org.tor.Request.parseParts(Request.java:2776)
at org.tor.Request.parseParameters(Request.java:3151)
at org.Parameter(Request.java:1108)
at org.Parameter(RequestFacade.java:380)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:70)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.tor.CoyoteAdapter.service(CoyoteAdapter.java:522)
at http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at at.util.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at at.util.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at urrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at at.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
14:04:46.145 [http-nio-8082-exec-3] ERROR C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet dispatcherServlet threw exception at.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field upfile exceeds its maximum permitted size of 1048576 bytes.
at at.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:633)
at at.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76)
at at.util.http.fileupload.ad(LimitedInputStream.java:135)
at java.ad(FilterInputStream.java:107)
at at.util.http.fileupload.py(Streams.java:98)
at at.util.http.fileupload.py(Streams.java:68)
at at.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:293)
at org.tor.Request.parseParts(Request.java:2776)
at org.tor.Request.parseParameters(Request.java:3151)
at org.Parameter(Request.java:1108)
at org.Parameter(RequestFacade.java:380)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:70)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.tor.CoyoteAdapter.service(CoyoteAdapter.java:522)
at http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at at.util.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at at.util.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at urrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at at.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
14:04:46.147 [http-nio-8082-exec-3] ERROR C.[Tomcat].[localhost] - Exception Processing ErrorPage[errorCode=0, location=/error] org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is
java.lang.IllegalStateException: at.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field upfile exceeds its maximum permitted size of 1048576 bytes.
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:979)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.ApplicationDispatcher.invoke(ApplicationDispatcher.java:720)
at org.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:468)
at org.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at org.StandardHostValve.custom(StandardHostValve.java:445)
at org.StandardHostValve.status(StandardHostValve.java:304)
at org.StandardHostValve.throwable(StandardHostValve.java:399)
at org.StandardHostValve.invoke(StandardHostValve.java:179)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.tor.CoyoteAdapter.service(CoyoteAdapter.java:522)
at http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at at.util.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at at.util.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at urrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at urrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at at.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is
java.lang.IllegalStateException: at.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field upfile exceeds its maximum permitted size of 1048576 bytes.
at
org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:111) at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:85)
at org.springframework.web.multipart.solveMultipart(StandardServletMultipartResolver.java:76)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1091)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:930)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
... 25 common frames omitted
Caused by: java.lang.IllegalStateException: at.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field upfile exceeds its maximum permitted size of 1048576 bytes.
at org.tor.Request.parseParts(Request.java:2846)
at org.tor.Request.parseParameters(Request.java:3151)
at org.Parameter(Request.java:1108)
at org.Parameter(RequestFacade.java:380)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:70)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.StandardHostValve.invoke(StandardHostValve.java:141)
... 11 common frames omitted
Caused by: at.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field upfile exceeds its maximum permitted size of 1048576 bytes.
at at.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:633) at at.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76)
at at.util.http.fileupload.ad(LimitedInputStream.java:135)
at java.ad(FilterInputStream.java:107)
at at.util.http.fileupload.py(Streams.java:98)
at at.util.http.fileupload.py(Streams.java:68)
at at.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:293)
at org.tor.Request.parseParts(Request.java:2776)
... 30 common frames omitted
71.5 Handling Multipart File Uploads
1.⾸先我们⽤的是ueditor,需要改ueditor的上传⼤⼩
2.springboot 程序启动需要加载这个java类
@Configuration
@ConditionalOnClass({ Servlet.class, StandardServletMultipartResolver.class,
MultipartConfigElement.class })
@ConditionalOnProperty(prefix = "spring.http.multipart", name = "enabled", matchIfMissing = true)
@EnableConfigurationProperties(MultipartProperties.class)
public class MultipartAutoConfiguration {
@Autowired
private MultipartProperties multipartProperties;
//    public MultipartAutoConfiguration(MultipartProperties multipartProperties) {
//        this.multipartProperties = multipartProperties;
//    }
@Bean
@ConditionalOnMissingBean
public MultipartConfigElement multipartConfigElement() {
this.multipartProperties.setMaxFileSize("-1");
return ateMultipartConfig();
}
@Bean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME)
@ConditionalOnMissingBean(MultipartResolver.class)
public StandardServletMultipartResolver multipartResolver() {
StandardServletMultipartResolver multipartResolver = new StandardServletMultipartResolver();
multipartResolver.setResolveLazily(false);
return multipartResolver;
}
问题就解决了

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。