Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. datasource.primary.url = <url>
  2. datasource.primary.username = <user>
  3. datasource.primary.password = <password>
  4.  
  5. datasource.secondary.url = <url>
  6. datasource.secondary.username = <user>
  7. datasource.secondary.password = <pass>
  8.  
  9. @EnableAutoConfiguration
  10. @Configuration
  11. @EntityScan({"com.example.domain","com.example.common.domain"})
  12. @PropertySource(value = "classpath:application.properties")
  13. @EnableScheduling
  14. public class MyApplication {
  15.  
  16. public static void main(String[] args) {
  17. SpringApplication.run(MyApplication.class, args);
  18. }
  19.  
  20. }
  21.  
  22. @Configuration
  23. @EnableJpaRepositories(basePackages = "com.example.repository",
  24. entityManagerFactoryRef = "primaryEntityManagerFactory",
  25. transactionManagerRef = "primaryTransactionManager")
  26. @EnableTransactionManagement
  27. public class PrimaryConfiguration {
  28.  
  29. @Bean
  30. @ConfigurationProperties(prefix = "datasource.primary")
  31. @Primary
  32. public DataSource primaryDataSource()
  33. {
  34. return DataSourceBuilder.create().build();
  35. }
  36.  
  37. @Bean
  38. @Primary
  39. public LocalContainerEntityManagerFactoryBean primaryEntityManagerFactory(final EntityManagerFactoryBuilder builder)
  40. {
  41. return builder
  42. .dataSource(primaryDataSource())
  43. .packages("uk.gov.dwp.pss.roc.domain")
  44. .persistenceUnit("primaryPersistenceUnit")
  45. .build();
  46. }
  47.  
  48. @Bean
  49. @Primary
  50. public JpaTransactionManager primaryTransactionManager(@Qualifier("primaryEntityManagerFactory") final EntityManagerFactory factory)
  51. {
  52. return new JpaTransactionManager(factory);
  53. }
  54. }
  55.  
  56. @Configuration
  57. @EnableJpaRepositories(basePackages = "com.example.common.repository",
  58. entityManagerFactoryRef = "secondaryEntityManagerFactory",
  59. transactionManagerRef = "secondaryTransactionManager")
  60. @EnableTransactionManagement
  61. public class SecondaryConfiguration {
  62.  
  63. @Bean
  64. @ConfigurationProperties(prefix = "datasource.secondary")
  65. public DataSource secondaryDataSource()
  66. {
  67. return DataSourceBuilder.create().build();
  68. }
  69.  
  70. @Bean
  71. public LocalContainerEntityManagerFactoryBean secondaryEntityManagerFactory(final EntityManagerFactoryBuilder builder)
  72. {
  73. return builder
  74. .dataSource(secondaryDataSource())
  75. .packages("uk.gov.dwp.pss.commons.domain.security")
  76. .persistenceUnit("secondaryPersistenceUnit")
  77. .build();
  78. }
  79.  
  80. @Bean
  81. public JpaTransactionManager secondaryTransactionManager(@Qualifier("secondaryEntityManagerFactory") final EntityManagerFactory factory)
  82. {
  83. return new JpaTransactionManager(factory);
  84. }
  85.  
  86. }
  87.  
  88. public interface MyRepository extends JpaRepository<MyObject, String>,JpaSpecificationExecutor<MyObject> {
  89. }
  90.  
  91. @SpringApplicationConfiguration(classes = MyApplication.class)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement