diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-06-23 09:37:57 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-06-23 09:37:57 +0200 |
commit | 7caa5b1f1e08f99cfe4465f091f47e2966d78aa7 (patch) | |
tree | c0bd7202845697207b04d518f613588df17d9e12 /src/test/java/io/trygvis/test/spring/TestConfig.java | |
download | jdbc-queue-master.tar.gz jdbc-queue-master.tar.bz2 jdbc-queue-master.tar.xz jdbc-queue-master.zip |
Diffstat (limited to 'src/test/java/io/trygvis/test/spring/TestConfig.java')
-rwxr-xr-x | src/test/java/io/trygvis/test/spring/TestConfig.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/test/java/io/trygvis/test/spring/TestConfig.java b/src/test/java/io/trygvis/test/spring/TestConfig.java new file mode 100755 index 0000000..4df8ce1 --- /dev/null +++ b/src/test/java/io/trygvis/test/spring/TestConfig.java @@ -0,0 +1,57 @@ +package io.trygvis.test.spring; + +import com.jolbox.bonecp.BoneCPDataSource; +import io.trygvis.test.DbUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; +import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; +import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.transaction.support.TransactionTemplate; + +import javax.sql.DataSource; +import java.sql.SQLException; + +@Configuration +@ComponentScan(basePackages = "io.trygvis") +@EnableTransactionManagement +public class TestConfig { + + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() throws Exception { + return new PropertySourcesPlaceholderConfigurer() {{ + setProperties(System.getProperties()); + setLocalOverride(true); + }}; + } + + @Bean + public JdbcTemplate jdbcTemplate(DataSource dataSource) { + return new JdbcTemplate(dataSource); + } + + @Bean + public DataSource dataSource(@Value("${database.url}") String jdbcUrl, + @Value("${database.username}") String username, + @Value("${database.password}") String password) throws SQLException { + BoneCPDataSource ds = DbUtil.createDataSource(jdbcUrl, username, password); + + return new TransactionAwareDataSourceProxy(new LazyConnectionDataSourceProxy(ds)); + } + + @Bean + public PlatformTransactionManager transactionManager(DataSource dataSource) { + return new DataSourceTransactionManager(dataSource); + } + + @Bean + public TransactionTemplate transactionTemplate(PlatformTransactionManager platformTransactionManager) { + return new TransactionTemplate(platformTransactionManager); + } +} |