SpringBoot的@MultipartConfig maxFileSize未生效
我有一个带有注释的控制器(其片段如下所示):MultipartConfig
@RestController
@RequestMapping("packages")
@MultipartConfig(maxFileSize = 1024*1024*1024, maxRequestSize = 1024*1024*1024)
public class PackagesController
{
@RequestMapping(method = RequestMethod.POST)
public String create(@RequestParam("package") MultipartFile uploadedPackage)
{
// do stuff to the file
return "create";
}
}
但是,当我将文件上传到此端点时,它似乎正在使用默认的多部分配置值:
Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field package exceeds its maximum permitted size of 1048576 bytes.
at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:633) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at java.io.FilterInputStream.read(FilterInputStream.java:107) ~[na:1.8.0_45]
at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:98) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:68) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:293) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
at org.apache.catalina.connector.Request.parseParts(Request.java:2776) ~[tomcat-embed-core-8.0.32.jar:8.0.32]
... 30 common frames omitted
我的应用程序如下所示:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
}
我是否缺少某些内容,使注释生效?@MultipartConfig