lver的maxUploadSize时的ClassNotFoun

lver的maxUploadSize时的ClassNotFoun

本文介绍了Spring Boot:配置CommonMultipartResolver的maxUploadSize时的ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的web应用程序使用Spring Boot,我试图配置Spring的CommonMultipartResolver的maxUploadSize。目前,它似乎受限于1 MB的Spring(?)默认大小。上传是通过一个REST接口完成的,方法签名如下所示:

  @RequestMapping(value =/ upload ,方法= RequestMethod.POST)
public void uploadFile(@RequestParam(file)MultipartFile文件,HttpServletRequest请求)

每次我尝试上传一个更大的文件时,都会抛出一个FileSizeLimitExceededException:

  org.apache.tomcat .util.http.fileupload.FileUploadBase $ FileSizeLimitExceededException:字段文件超出了允许的最大大小1048576字节。 
at org.apache.tomcat.util.http.fileupload.FileUploadBase $ FileItemIteratorImpl $ FileItemStreamImpl $ 1.raiseError(FileUploadBase.java:637)
at org.apache.tomcat.util.http.fileupload.util .LimitedInputStream.checkLimit(LimitedInputStream.java:76)
在org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135)
在java.io.FilterInputStream .read(FilterInputStream.java:107)
at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:99)
at org.apache.tomcat.util .http.fileupload.util.Streams.copy(Streams.java:68)
at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:296)
at org .apache.catalina.connector.Request.parseParts(Request.java:2737)
at org.apache.catalina.connector.Request.parseParameters(Request.java:3096)
at org.apache.catalina .connector.Request.getParameter(Request.java:1145)
在org.apache.catalina.connect or.RequestFacade.getParameter(RequestFacade.java:382)
在javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:140)
在javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:140)在javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:140)

在org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:70)
在org.springframework .web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
在org.apache.catalina.core .ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)
在org.springframework.security.web.access .intercept.FilterSecurityInterceptor.invoke(FilterSecurityIntercepto r.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain。的doFilter(FilterChainProxy.java:342)
处org.springframework.security.web.FilterChainProxy $ VirtualFilterChain org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
。 doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain。的doFilter(FilterChainProxy.java:342)
处org.springframework.security.web.FilterChainProxy $ VirtualFilterChain org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
。 doFilter(FilterChainProxy.java:342)
在org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)
在org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)
在org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)
。在org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
在org.springframework.security.w在org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter eb.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)
(SecurityContextPersistenceFilter.java:87)
。在org.springframework.security。在org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)
(WebAsyncManagerIntegrationFilter.java:50)
。在组织。 springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)维持在org.springframework org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)

。 security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
在org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
在org.apache.catalina.core。 ApplicationFilterChain.internalDoFilter(应用A nFilterChain.java:241)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
在org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter。 java:109)
at org.springframework.boot.context.web.ErrorPageFilter.access $ 000(ErrorPageFilter.java:59)
at org.springframework.boot.context.web.ErrorPageFilter $ 1.doFilterInternal( ErrorPageFilter.java:88)
在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
在org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter。
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextV alve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke( (org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java):
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java: 950)
在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org .apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at j ava.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:744)



不工作:

设置Tomcat属性

由于我的web应用程序运行在Tomcat上(不是嵌入式的,但一个单独的外部),我尝试通过更改Tomcat配置来配置大小,如描述。不幸的是,这没有任何效果,因为最大上传大小仍然是1MB。
$ b

通过注释配置Spring的CommonMultipartResolver

由于1MB的值似乎来自CommonMultipartResolver(我可以看到调试时设置了1MB的值),所以我尝试通过注释来配置Spring,如下所示:

  @Configuration 
public class CoreConfig {

@Bean
CommonsMultipartResolver commonsMultipartResolver(){
CommonsMultipartResolver multipartResolver = new是CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(50 * 1024 * 1024);
返回multipartResolver;
}

}

但是当我启动Tomcat时,引发以下异常:

 导致:java.lang.NoClassDefFoundError:org / apache / commons / fileupload / FileItemFactory 
在myapp.server.CoreConfig.commonsMulipartResolver(CoreConfig.java:40)
在myapp.server.CoreConfig $$ EnhancerBySpringCGLIB $$ 8b64a88.CGLIB $ commonsMulipartResolver $ 3(<生成>)$ b $ myApp .server.CoreConfig $$ EnhancerBySpringCGLIB $$ 8b64a88 $$ FastClassBySpringCGLIB $$ ac8c6ee5.invoke(小于生成>)在org.springframework.cglib.proxy.MethodProxy.invokeSuper
(MethodProxy.java:228)
。在org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)在myapp.server.CoreConfig $$ EnhancerBySpringCGLIB $$ 8b64a88.commonsMulipartResolver
(其中p产生>)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)
在太阳。 reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect.Method.invoke(Method.java: 606)
在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
... 27个常见框架省略
引起:java.lang.ClassNotFoundException :org.apache.commons.fileupload.FileItemFactory
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass( WebappClassLoader.java:1571)



通过XML配置



而不是一个注释驱动的配置,我尝试了一个类似于。

对于所有属性,请检查类。其他支持的属性是 spring.http.multipart.location spring.http.multipart.maxRequestSize spring.http.multipart.fileSizeThreshold



ClassNotFoundException Spring Boot使用默认的Servlet 3.0支持文件上传NOT commons-fileupload。所以,如果你想使用它,你必须明确地添加它的依赖。当然,在这种情况下, spring.http.multipart。* 属性不再适用。


I'm using Spring Boot for my web application and I'm trying to configure the maxUploadSize of Spring's CommonMultipartResolver. Currently, it seems to be limited by a Spring (?) default size of 1 MB. The upload is done through a REST interface, and the method signature looks like this:

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void uploadFile(@RequestParam("file") MultipartFile file, HttpServletRequest request)

Everytime I try to upload a bigger file, a FileSizeLimitExceededException is thrown:

org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
    at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:637)
    at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76)
    at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135)
    at java.io.FilterInputStream.read(FilterInputStream.java:107)
    at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:99)
    at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:68)
    at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:296)
    at org.apache.catalina.connector.Request.parseParts(Request.java:2737)
    at org.apache.catalina.connector.Request.parseParameters(Request.java:3096)
    at org.apache.catalina.connector.Request.getParameter(Request.java:1145)
    at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:382)
    at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:140)
    at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:140)
    at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:140)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:70)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:109)
    at org.springframework.boot.context.web.ErrorPageFilter.access$000(ErrorPageFilter.java:59)
    at org.springframework.boot.context.web.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:101)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:744)

Things I have tried, but did not work:

Setting Tomcat properties

Since my web app is running on Tomcat (not the embedded one, but a separate external one), I tried configuring the size by changing the Tomcat configuration as is described here. Unfortunately, this has no effect, as the max upload size still remains at 1 MB.

Configuring Spring's CommonMultipartResolver by annotation

Since the value of 1MB seems to come from the CommonMultipartResolver (I can see that the value of 1MB is set when debugging), I tried configuring Spring via annotation like this:

@Configuration
public class CoreConfig {

    @Bean
    public CommonsMultipartResolver commonsMultipartResolver() {
    CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
    multipartResolver.setMaxUploadSize(50 * 1024 * 1024);
    return multipartResolver;
    }

}

But when I start up Tomcat, the following exception is thrown:

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
    at myapp.server.CoreConfig.commonsMulipartResolver(CoreConfig.java:40)
    at myapp.server.CoreConfig$$EnhancerBySpringCGLIB$$8b64a88.CGLIB$commonsMulipartResolver$3(<generated>)
    at myapp.server.CoreConfig$$EnhancerBySpringCGLIB$$8b64a88$$FastClassBySpringCGLIB$$ac8c6ee5.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
    at myapp.server.CoreConfig$$EnhancerBySpringCGLIB$$8b64a88.commonsMulipartResolver(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    ... 27 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)

Configuration via XML

Instead of an annotation-driven configuration, I tried a configuration via XML similar to this posting, but I'm getting the same ClassNotFoundException as above.

Additional Info

Spring Boot Starter 1.1.9

Tomcat 7.0.54

Pom.xml of the server

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mygroup</groupId>
    <artifactId>myapp.server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.9.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>17.0</version>
        </dependency>
        <dependency>
            <groupId>org.ini4j</groupId>
            <artifactId>ini4j</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
        </dependency>
    </dependencies>

    <properties>
        <start-class>myapp.server.Application</start-class>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>${artifactId}</finalName>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>http://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>http://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>
解决方案

You are making it way to complex.

Just add spring.http.multipart.maxFileSize to your application.properties file and well that is it. No need to use xml or explicitly define a MultipartResolver.

spring.http.multipart.maxFileSize=10MB

This is explained in the section about file uploads in the Spring Boot Reference Guide.

For all properties check the MultipartProperties class. The other properties supported are spring.http.multipart.location, spring.http.multipart.maxRequestSize and spring.http.multipart.fileSizeThreshold.

The ClassNotFoundException is due to the fact that Spring Boot uses the default Servlet 3.0 support for file uploads NOT commons-fileupload. So if you want to use that, you would have to explicitly add the dependency for it. And ofcourse the spring.http.multipart.* properties don't work anymore in that case.

这篇关于Spring Boot:配置CommonMultipartResolver的maxUploadSize时的ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 18:04