Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @Profile("test")
- @EnableJpaRepositories(
- basePackages = "tracker.repository.wmx",
- entityManagerFactoryRef = "wmxH2EntityManager",
- transactionManagerRef = "wmxH2TransactionManager")
- public class WmxH2DatasourceConfig {
- @Autowired
- private Environment env;
- @Bean
- public LocalContainerEntityManagerFactoryBean wmxH2EntityManager() {
- LocalContainerEntityManagerFactoryBean em
- = new LocalContainerEntityManagerFactoryBean();
- em.setDataSource(wmxH2DataSource());
- em.setPackagesToScan(
- new String[]{"tracker.domain.wmx"});
- HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
- em.setJpaVendorAdapter(vendorAdapter);
- HashMap<String, Object> properties = new HashMap<>();
- properties.put("hibernate.hbm2ddl.auto",
- env.getProperty("hibernate.hbm2ddl.auto"));
- properties.put("hibernate.dialect",
- env.getProperty("hibernate.dialect"));
- em.setJpaPropertyMap(properties);
- return em;
- }
- @Bean
- public DataSource wmxH2DataSource() {
- DriverManagerDataSource dataSource
- = new DriverManagerDataSource();
- dataSource.setDriverClassName(
- env.getProperty("test.h2.datasource.driver-class-name"));
- dataSource.setUrl(env.getProperty("test.h2.datasource.url"));
- dataSource.setUsername(env.getProperty("test.h2.datasource.data-username"));
- dataSource.setPassword(env.getProperty("test.h2.datasource.data-password"));
- return dataSource;
- }
- @Bean
- public PlatformTransactionManager wmxH2TransactionManager() {
- JpaTransactionManager transactionManager = new JpaTransactionManager();
- transactionManager.setEntityManagerFactory(wmxH2EntityManager().getObject());
- return transactionManager;
- }
- }
- @Configuration
- @Profile({"prod","test"})
- @EnableJpaRepositories(
- basePackages = "tracker.repository.h2",
- entityManagerFactoryRef = "h2EntityManager",
- transactionManagerRef = "h2TransactionManager")
- public class PrivateH2DatasourceConfig {
- @Autowired
- private Environment env;
- @Bean
- @Primary
- public LocalContainerEntityManagerFactoryBean h2EntityManager() {
- LocalContainerEntityManagerFactoryBean em
- = new LocalContainerEntityManagerFactoryBean();
- em.setDataSource(h2DataSource());
- em.setPackagesToScan(
- new String[]{"tracker.domain.h2"});
- HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
- em.setJpaVendorAdapter(vendorAdapter);
- HashMap<String, Object> properties = new HashMap<>();
- properties.put("hibernate.hbm2ddl.auto",
- env.getProperty("hibernate.hbm2ddl.auto"));
- properties.put("hibernate.dialect",
- env.getProperty("hibernate.dialect"));
- em.setJpaPropertyMap(properties);
- return em;
- }
- @Bean
- @Primary
- public DataSource h2DataSource() {
- DriverManagerDataSource dataSource
- = new DriverManagerDataSource();
- dataSource.setDriverClassName(
- env.getProperty("h2.datasource.driver-class-name"));
- dataSource.setUrl(env.getProperty("h2.datasource.url"));
- dataSource.setUsername(env.getProperty("h2.datasource.data-username"));
- dataSource.setPassword(env.getProperty("h2.datasource.data-password"));
- return dataSource;
- }
- @Bean
- @Primary
- public PlatformTransactionManager h2TransactionManager() {
- JpaTransactionManager transactionManager = new JpaTransactionManager();
- transactionManager.setEntityManagerFactory(h2EntityManager().getObject());
- return transactionManager;
- }
- }
- #can be over ridden by run arguments
- spring.profiles.active=test
- flyway.baseline-on-migrate=true
- ## H2
- h2.datasource.driver-class-name=org.h2.Driver
- h2.datasource.url=jdbc:h2:./data/deliverytracker.h2
- h2.datasource.data-username=x
- h2.datasource.data-password=xxx
- ## H2 WMX (Test environment)
- test.h2.datasource.driver-class-name=org.h2.Driver
- test.h2.datasource.url=jdbc:h2:./data/wmx_test.h2
- test.h2.datasource.data-username=x
- test.h2.datasource.data-password=xxx
- test.h2.datasource.initialize=true
- test.h2.datasource.data=classpath:schema-test.sql,classpath:data-test.sql
Add Comment
Please, Sign In to add comment