我试图使用springboot制作一个简单的上传应用程序,它可以正常工作,直到我尝试上传10Mb +文件,我在屏幕上收到此消息:
There was an unexpected error (type=Internal Server Error, status=500).
Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (14326061) exceeds the configured maximum (10485760)
我做过一些研究,到目前为止还没有任何工作。我将离开这里,到目前为止我所尝试的事情之下。
将此代码(以各种方式)放入我的" application.yml"
multipart:
maxFileSize: 51200KB
maxRequestFile: 51200KB
我也在我的校长课上试过这个:
@Bean
public TomcatEmbeddedServletContainerFactory containerFactory() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
}
});
return factory;
}
还有一些奇怪的事情。如果我输入我的tomcat web.xml,则multipart-config为:
<multipart-config>
<!-- 50MB max -->
<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
所以这就是#34; ...配置最大值(10485760)&#34;来自哪里? (旁注:我使用netbeans 8.1和springboot 1.5)。
Thx家伙。(对于英语s2感到抱歉)
自从被问到,这是我的application.yml
server:
port: 9999
context-path: /client
logging:
level:
org.springframework.security: DEBUG
endpoints:
trace:
sensitive: false
spring:
thymeleaf:
cache: false
multipart:
maxFileSize: 51200KB
maxRequestFile: 51200KB
#################################################################################
security:
basic:
enabled: false
oauth2:
client:
client-id: acme2
client-secret: acmesecret2
access-token-uri: http://localhost:8080/oauth/token
user-authorization-uri: http://localhost:8080/oauth/authorize
resource:
user-info-uri: http://localhost:8080/me
#
答案 0 :(得分:0)
spring:
http:
multipart:
enabled: true
max-file-size: 50MB
max-request-size: 50MB
或
spring.http.multipart.max-file-size=50MB
spring.http.multipart.max-request-size=50MB
希望它能起作用
答案 1 :(得分:0)
对于SpringBoot 1.5.7到2.1.2,需要在application.properties文件中设置的属性为:
spring.http.multipart.max-file-size=100MB
spring.http.multipart.max-request-size=100MB
还要确保在“ resources”文件夹中有application.properties文件。
答案 2 :(得分:0)
用于配置CommonsMultipartResolver 定义名称为 MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME 的bean 作为默认的Spring Boot的默认MultipartFilter会查找具有默认bean名称的解析器。
@Bean(name = MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME)
protected MultipartResolver getMultipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(20971520);
multipartResolver.setMaxInMemorySize(20971520);
return multipartResolver;
}
答案 3 :(得分:0)
以下是基于版本的方法,
1st:
spring.servlet.multipart.max-file-size=1000MB
spring.servlet.multipart.max-request-size=1000MB
2'nd:
spring.http.multipart.max-file-size=50MB
spring.http.multipart.max-request-size=50MB
3'rd:
multipart.enabled=true
multipart.max-file-size=100MB
multipart.max-request-size=100MB
答案 4 :(得分:0)
spring:
servlet:
multipart:
enabled: true
file-size-threshold: 200KB
max-file-size: 500MB
max-request-size: 500MB