sync source code with article
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.baeldung.spring.web.config;
|
||||
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRegistration;
|
||||
|
||||
import org.springframework.web.WebApplicationInitializer;
|
||||
import org.springframework.web.context.support.GenericWebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
public class MainWebAppInitializer implements WebApplicationInitializer {
|
||||
|
||||
private String TMP_FOLDER = "/tmp";
|
||||
private int MAX_UPLOAD_SIZE = 5 * 1024 * 1024;
|
||||
|
||||
@Override
|
||||
public void onStartup(ServletContext sc) throws ServletException {
|
||||
|
||||
ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(
|
||||
new GenericWebApplicationContext()));
|
||||
|
||||
appServlet.setLoadOnStartup(1);
|
||||
|
||||
MultipartConfigElement multipartConfigElement = new MultipartConfigElement(TMP_FOLDER,
|
||||
MAX_UPLOAD_SIZE, MAX_UPLOAD_SIZE * 2, MAX_UPLOAD_SIZE / 2);
|
||||
|
||||
appServlet.setMultipartConfig(multipartConfigElement);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||
@@ -121,4 +122,11 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
public ExcelPOIHelper excelPOIHelper() {
|
||||
return new ExcelPOIHelper();
|
||||
}
|
||||
|
||||
@Bean(name = "multipartResolver")
|
||||
public CommonsMultipartResolver multipartResolver() {
|
||||
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
||||
multipartResolver.setMaxUploadSize(100000);
|
||||
return multipartResolver;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user