java“请求被拒绝,因为它的大小”Spring,tomcat
我正在尝试使用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网站。xml,多部分配置为:
<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>
那么这个“…配置最大值(10485760)”是从哪里来的呢? (旁注:我使用的是netbeans 8.1和springboot 1.5)
Thx伙计们。(为英语s2感到抱歉)
既然问了,这是我的申请。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
#
# 1 楼答案
或者
参考here
希望它能奏效
# 2 楼答案
用于配置CommonsMultipartResolver 定义一个bean名为MultipartFilter的bean。默认\u多部分\u解析器\u BEAN\u名称 作为默认的spring引导,默认的MultipartFilter会查找具有默认bean名称的解析器
# 3 楼答案
对于SpringBoot 1.5.7到2.1.2,需要在应用程序中设置属性。文件的属性包括:
还要确保你有申请表。“资源”文件夹中的属性文件
# 4 楼答案
以下是基于版本的方法
1点钟:
第二点:
三点:
# 5 楼答案