spring-boot - 迁移到 Spring Boot 时将这段代码放在哪里?
问题描述
我有一个带有此代码的应用程序来调整“MultipartConfigElement”:
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
private int maxUploadSizeInMb = 5 * 1024 * 1024; // 5 MB
@Override
protected Class<?>[] getRootConfigClasses () {
return null;
}
@Override
protected Class<?>[] getServletConfigClasses () {
return new Class<?>[]{ WebConfig.class };
}
@Override
protected String[] getServletMappings () {
return new String[]{"/"};
}
@Override
protected void customizeRegistration(ServletRegistration.Dynamic registration) {
File uploadDirectory = new File(System.getProperty("java.io.tmpdir"));
MultipartConfigElement multipartConfigElement =
new MultipartConfigElement(uploadDirectory.getAbsolutePath(),
maxUploadSizeInMb, maxUploadSizeInMb * 2, maxUploadSizeInMb / 2);
registration.setMultipartConfig(multipartConfigElement);
}
}
现在我正在转向由以下人员创建的 SpringBoot https://start.spring.io/
:
@SpringBootApplication
public class HadesApplication {
public static void main(String[] args) {
SpringApplication.run(HadesApplication.class, args);
}
}
我想我不会再使用AbstractAnnotationConfigDispatcherServletInitializer
了,所以我的旧代码放在哪里?
解决方案
查看该配置,我相信所有设置都可以在application.properties
.
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
MULTIPART(多部分属性)
spring.servlet.multipart.enabled=true # Whether to enable support of multipart uploads.
spring.servlet.multipart.file-size-threshold=0 # Threshold after which files are written to disk. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes, respectively.
spring.servlet.multipart.location= # Intermediate location of uploaded files.
spring.servlet.multipart.max-file-size=1MB # Max file size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes, respectively.
spring.servlet.multipart.max-request-size=10MB # Max request size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes, respectively.
spring.servlet.multipart.resolve-lazily=false # Whether to resolve the multipart request lazily at the time of file or parameter access.
推荐阅读
- shell - Read line by line column exculding header from Processed_files.csv and search each line in Responsed_File_Name.csv
- sqlite - 如何定期将内存中的sqlite保存到磁盘
- c++ - Is there a function like find_last_of in std but not in string?
- python - 需要读取出现在具有不同列顺序的许多不同输入文件中的 4 个特定列/数据字段
- python - 未定义海龟属性
- mysql - 如何安全地存储密码以备后用
- python - 通过使用 .strip() python pandas 删除空格无意中删除的数字
- swift - 在字典数组中找到最大值
- django - xhtml2pdf 在 Django 中使用 WinAnsiEncoding 创建 URL
- python - 如何通过 python 脚本而不是 ipython 使用 SPy 显示高光谱图像?