aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-28 22:38:21 +0300
committerGravatar Vitaly Takmazov2017-01-10 12:08:35 +0300
commit2f682b5e3cfc3fc5f961b60129be7bc90e0d6a03 (patch)
tree840aea9eb94d5c1f667a710d3298135854bc5002 /juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java
parenteb440ea4f120115613880e340b010eed5397e72c (diff)
juick-www: now on spring-webmvc
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java')
-rw-r--r--juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java99
1 files changed, 99 insertions, 0 deletions
diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java
new file mode 100644
index 00000000..c4e6c07c
--- /dev/null
+++ b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java
@@ -0,0 +1,99 @@
+package com.juick.www.configuration;
+
+import com.mitchellbosecke.pebble.PebbleEngine;
+import com.mitchellbosecke.pebble.loader.Loader;
+import com.mitchellbosecke.pebble.loader.ServletLoader;
+import com.mitchellbosecke.pebble.spring4.PebbleViewResolver;
+import com.mitchellbosecke.pebble.spring4.extension.SpringExtension;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.env.Environment;
+import org.springframework.http.CacheControl;
+import org.springframework.web.multipart.MultipartResolver;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
+import org.springframework.web.servlet.ViewResolver;
+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;
+import org.springframework.web.servlet.resource.PathResourceResolver;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Created by vitalyster on 28.06.2016.
+ */
+@Configuration
+@ComponentScan(basePackages = {"com.juick.www.controllers"})
+@PropertySource("classpath:juick.conf")
+public class WwwServletConfiguration extends WebMvcConfigurationSupport {
+ @Inject
+ private Environment env;
+
+ @Override
+ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.setOrder(0);
+ registry.addResourceHandler(
+ "/scripts.js*",
+ "/style.css*",
+ "/*.png",
+ "/favicon.ico")
+ .addResourceLocations("/")
+ .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS))
+ .resourceChain(true)
+ .addResolver(new PathResourceResolver());
+
+ registry.addResourceHandler("/static/**")
+ .addResourceLocations("/static/")
+ .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS));
+ }
+
+ @Override
+ public RequestMappingHandlerMapping requestMappingHandlerMapping() {
+ RequestMappingHandlerMapping result = super.requestMappingHandlerMapping();
+
+ result.setOrder(1);
+
+ return result;
+ }
+
+ @Bean
+ public MultipartResolver multipartResolver() {
+ CommonsMultipartResolver resolver = new CommonsMultipartResolver();
+ resolver.setMaxUploadSize(10000000);
+ return resolver;
+ }
+
+ @Inject
+ private ServletContext servletContext;
+
+ @Bean
+ public Loader templateLoader(){
+ return new ServletLoader(servletContext);
+ }
+
+ @Bean
+ public SpringExtension springExtension() {
+ return new SpringExtension();
+ }
+
+ @Bean
+ public PebbleEngine pebbleEngine() {
+ return new PebbleEngine.Builder()
+ .loader(this.templateLoader())
+ .extension(springExtension())
+ .build();
+ }
+
+ @Bean
+ public ViewResolver viewResolver() {
+ PebbleViewResolver viewResolver = new PebbleViewResolver();
+ viewResolver.setPrefix("/WEB-INF/");
+ viewResolver.setSuffix(".html");
+ viewResolver.setPebbleEngine(pebbleEngine());
+ return viewResolver;
+ }
+}