Guest User

Untitled

a guest
Jun 13th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. @Configuration
  2. public class DataSourceConfiguration {
  3.  
  4. @Bean
  5. @ConfigurationProperties(prefix = "first.datasource")
  6. @Primary
  7. public DataSourceProperties firstProperties() {
  8. return new DataSourceProperties();
  9. }
  10.  
  11. @Bean
  12. @Primary
  13. public DataSource firstDataSource() {
  14. return firstProperties().initializeDataSourceBuilder().build();
  15. }
  16.  
  17. @Bean
  18. @Primary
  19. public JdbcTemplate firstTemplate() {
  20. return new JdbcTemplate(firstDataSource());
  21. }
  22. }
  23.  
  24. @Configuration
  25. @ConditionalOnProperty(name = "second.datasource.url")
  26. public class SecondDataSourceAutoconfiguration {
  27.  
  28. @Bean
  29. @ConfigurationProperties(prefix = "second.datasource")
  30. public DataSourceProperties secondProperties() {
  31. return new DataSourceProperties();
  32. }
  33.  
  34. @Bean
  35. public DataSource secondDataSource() {
  36. return secondProperties().initializeDataSourceBuilder().build();
  37. }
  38.  
  39. @Bean
  40. public JdbcTemplate secondJdbcTemplate(@Qualifier("secondDataSource") DataSource datasource) {
  41. return new JdbcTemplate(datasource);
  42. }
  43. }
  44.  
  45. first:
  46. datasource:
  47. url: jdbc:h2:firstdb;DB_CLOSE_ON_EXIT=FALSE
  48. second:
  49. datasource:
  50. url: jdbc:h2:seconddb
  51. platform: h2
Add Comment
Please, Sign In to add comment