根據(jù)異常內(nèi)提示的類,可以定位到:
FileUploadBase(class FileItemStreamImpl 的構(gòu)造函數(shù))
/**
* Creates a new instance.
*
* @param pName The items file name, or null.
* @param pFieldName The items field name.
* @param pContentType The items content type, or null.
* @param pFormField Whether the item is a form field.
* @param pContentLength The items content length, if known, or -1
* @throws IOException Creating the file item failed.
*/
FileItemStreamImpl(String pName, String pFieldName,
String pContentType, boolean pFormField,
long pContentLength) throws IOException {
name = pName;
fieldName = pFieldName;
contentType = pContentType;
formField = pFormField;
final ItemInputStream itemStream = multi.newInputStream();
InputStream istream = itemStream;
if (fileSizeMax != -1) {
if (pContentLength != -1
&& pContentLength > fileSizeMax) {
FileSizeLimitExceededException e =
new FileSizeLimitExceededException(
String.format("The field %s exceeds its maximum permitted size of %s bytes.",
fieldName, Long.valueOf(fileSizeMax)),
pContentLength, fileSizeMax);
e.setFileName(pName);
e.setFieldName(pFieldName);
throw new FileUploadIOException(e);
}
istream = new LimitedInputStream(istream, fileSizeMax) {
@Override
protected void raiseError(long pSizeMax, long pCount)
throws IOException {
itemStream.close(true);
FileSizeLimitExceededException e =
new FileSizeLimitExceededException(
String.format("The field %s exceeds its maximum permitted size of %s bytes.",
fieldName, Long.valueOf(pSizeMax)),
pCount, pSizeMax);
e.setFieldName(fieldName);
e.setFileName(name);
throw new FileUploadIOException(e);
}
};
}
stream = istream;
}
發(fā)現(xiàn)fileSizeMax該值控制上傳上限,在207行看到
/**
* Sets the maximum allowed size of a single uploaded file,
* as opposed to {@link #getSizeMax()}.
*
* @see #getFileSizeMax()
* @param fileSizeMax Maximum size of a single uploaded file.
*/
public void setFileSizeMax(long fileSizeMax) {
this.fileSizeMax = fileSizeMax;
}
追蹤后發(fā)現(xiàn)在Request類的parseParts方法(2863行)upload.setFileSizeMax(mce.getMaxFileSize());
mce對(duì)象是在2800行MultipartConfigElement mce = getWrapper().getMultipartConfigElement();初始化的。
通過(guò)getMultipartConfigElement()可在StandardWrapper內(nèi)的1072行處發(fā)現(xiàn)如下代碼
if (multipartConfigElement == null) {
MultipartConfig annotation =
servlet.getClass().getAnnotation(MultipartConfig.class);
if (annotation != null) {
multipartConfigElement =
new MultipartConfigElement(annotation);
}
}
最終發(fā)現(xiàn) 通過(guò)MultipartConfig注解可配置。
配置完不好使?。。?br>
后發(fā)現(xiàn)可通過(guò)配置文件:
spring:
http:
multipart:
maxFileSize: 10Mb
maxRequestSize: 100Mb