From 87ce0ec2f1c293bebdf4a015703406359acaede5 Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Sun, 11 Dec 2016 20:24:36 +0700 Subject: Multipart resolver --- .../www/configuration/WwwServletConfiguration.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'juick-spring-www/src') diff --git a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 2eb39e1c..8da3321e 100644 --- a/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-spring-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -9,9 +9,12 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.format.FormatterRegistry; +import org.springframework.http.CacheControl; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.multipart.MultipartResolver; +import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; @@ -23,6 +26,7 @@ import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.templatemode.TemplateMode; import java.util.List; +import java.util.concurrent.TimeUnit; /** * Created by vitalyster on 28.06.2016. @@ -102,9 +106,13 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { "/*.png", "/favicon.ico") .addResourceLocations("/") + .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS)) .resourceChain(true) .addResolver(new PathResourceResolver()); - registry.addResourceHandler("/static/**").addResourceLocations("/static/"); + + registry.addResourceHandler("/static/**") + .addResourceLocations("/static/") + .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS)); } @Override @@ -125,4 +133,11 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { public SpringDateFormatter dateFormatter() { return new SpringDateFormatter(); } + + @Bean + public MultipartResolver multipartResolver() { + CommonsMultipartResolver resolver = new CommonsMultipartResolver(); + resolver.setMaxUploadSize(10000000); + return resolver; + } } -- cgit v1.2.3