here
@Configuration
public class DataSourceConfiguration {
@Bean
public PlatformTransactionManager firstDataSourceTransactionManager() {
return new DataSourceTransactionManager(firstDataSource());
}
@Bean(destroyMethod = "shutdown")
@Primary
public DataSource firstDataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.generateUniqueName(true)
.build();
}
@Bean
public JdbcTemplate firstJdbcTemplate() {
return new JdbcTemplate(firstDataSource());
}
@Bean
public PlatformTransactionManager secondDataSourceTransactionManager() {
return new DataSourceTransactionManager(secondDataSource());
}
@Bean(destroyMethod = "shutdown")
public DataSource secondDataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.generateUniqueName(true)
.build();
}
@Bean
public JdbcTemplate secondJdbcTemplate() {
return new JdbcTemplate(secondDataSource());
}
}