aboutsummaryrefslogtreecommitdiff
path: root/juick-crosspost/src/main/java/com/juick/components
diff options
context:
space:
mode:
Diffstat (limited to 'juick-crosspost/src/main/java/com/juick/components')
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java30
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java14
2 files changed, 20 insertions, 24 deletions
diff --git a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java
index 0b213cc9..069037ee 100644
--- a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java
+++ b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostConfiguration.java
@@ -8,7 +8,6 @@ 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.apache.commons.dbcp2.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -34,28 +33,17 @@ import java.util.concurrent.Executors;
*/
@Configuration
@ComponentScan(basePackages = {"com.juick"})
-@PropertySource(value = "classpath:juick.conf", ignoreResourceNotFound = true)
+@PropertySource(value = {"classpath:juick.conf", "file:${user.home}/juick.conf"})
public class CrosspostConfiguration extends WebMvcConfigurationSupport {
@Inject
- Environment env;
- @Inject
- ExecutorService service;
- @Inject
- JdbcTemplate jdbc;
-
- @Bean
- JdbcTemplate jdbc() {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName(env.getProperty("datasource_driver", "com.mysql.jdbc.Driver"));
- dataSource.setUrl(env.getProperty("datasource_url"));
- return new JdbcTemplate(dataSource);
- }
-
+ private Environment env;
@Inject
private ServletContext servletContext;
+ @Inject
+ private JdbcTemplate jdbc;
@Bean
- public Loader templateLoader(){
+ public Loader templateLoader() {
return new ServletLoader(servletContext);
}
@@ -78,12 +66,15 @@ public class CrosspostConfiguration extends WebMvcConfigurationSupport {
viewResolver.setPrefix("/WEB-INF/templates/");
viewResolver.setSuffix(".html");
viewResolver.setPebbleEngine(pebbleEngine());
+
return viewResolver;
}
+
@Bean
public Crosspost crosspost() {
- return new Crosspost(env, service, jdbc);
+ return new Crosspost(env, service(), jdbc);
}
+
@Bean
public ExecutorService service() {
return Executors.newCachedThreadPool();
@@ -95,6 +86,7 @@ public class CrosspostConfiguration extends WebMvcConfigurationSupport {
mapping.setUseSuffixPatternMatch(false);
return mapping;
}
+
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.setOrder(0);
@@ -109,9 +101,11 @@ public class CrosspostConfiguration extends WebMvcConfigurationSupport {
.serializationInclusion(JsonInclude.Include.NON_NULL)
.serializationInclusion(JsonInclude.Include.NON_ABSENT)
.serializationInclusion(JsonInclude.Include.NON_EMPTY);
+
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(builder.build());
converter.getObjectMapper().registerModule(new Jdk8Module());
converters.add(converter);
+
super.configureMessageConverters(converters);
}
}
diff --git a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java
index e85d7a2a..0768f834 100644
--- a/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java
+++ b/juick-crosspost/src/main/java/com/juick/components/configuration/CrosspostInitializer.java
@@ -1,4 +1,6 @@
package com.juick.components.configuration;
+
+import com.juick.configuration.DataConfiguration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
@@ -10,24 +12,24 @@ import javax.servlet.Filter;
public class CrosspostInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
- return new Class[] {CrosspostConfiguration.class};
+ return new Class<?>[]{DataConfiguration.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
- return null;
+ return new Class<?>[]{CrosspostConfiguration.class};
}
@Override
protected String[] getServletMappings() {
- return new String[] {
- "/"
- };
+ return new String[]{"/"};
}
+
@Override
protected Filter[] getServletFilters() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
- return new Filter[] { characterEncodingFilter};
+
+ return new Filter[]{characterEncodingFilter};
}
}