From 7270411d55c154e42c942caeaf4d4b942d72dea2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 8 Nov 2016 16:36:52 +0300 Subject: ws: fix injection --- .../components/configuration/CrosspostConfiguration.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'juick-crosspost/src/main/java/com/juick/components/configuration') 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 7ed9fcee..99555a1b 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,6 +8,7 @@ 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; @@ -16,6 +17,7 @@ import org.springframework.core.env.Environment; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; @@ -38,6 +40,16 @@ public class CrosspostConfiguration extends WebMvcConfigurationSupport { 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); + } @Inject private ServletContext servletContext; @@ -70,7 +82,7 @@ public class CrosspostConfiguration extends WebMvcConfigurationSupport { } @Bean public Crosspost crosspost() { - return new Crosspost(env, service); + return new Crosspost(env, service, jdbc); } @Bean public ExecutorService service() { -- cgit v1.2.3