Guest User

Untitled

a guest
Jul 26th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. @Configuration
  2. @EnableTransactionManagement
  3. @EnableJpaRepositories(
  4. entityManagerFactoryRef = "entityManagerFactory",
  5. basePackages = "com.evli.kickback.database.local.repository"
  6. )
  7. public class LocalDatabaseConfig {
  8.  
  9. @Bean(name = "dataSource")
  10. @ConfigurationProperties(prefix = "spring.datasource")
  11. public DataSource dataSource() {
  12. return DataSourceBuilder.create().build();
  13.  
  14. }
  15. @Bean(name = "entityManagerFactory")
  16. public LocalContainerEntityManagerFactoryBean
  17. entityManagerFactory(EntityManagerFactoryBuilder builder, @Qualifier("dataSource") DataSource dataSource) {
  18. return builder.dataSource(dataSource)
  19. .packages("com.xxx.xxx")
  20. .persistenceUnit("local")
  21. .build();
  22. }
  23. @Bean(name = "transactionManager")
  24. public PlatformTransactionManager transactionManager(@Qualifier("entityManagerFactory")EntityManagerFactory entityManagerFactory) {
  25. return new JpaTransactionManager(entityManagerFactory);
  26. }
  27.  
  28. }
  29.  
  30. Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'XXXX.XXX' doesn't exist
  31.  
  32. import javax.persistence.EntityManagerFactory;
  33. import javax.sql.DataSource;
  34.  
  35. @Configuration
  36. @EnableJpaRepositories(
  37. entityManagerFactoryRef = "realEntityManagerFactory",
  38. transactionManagerRef = "realTransactionManager",
  39. basePackages = {"com.xxx.xxx"})
  40. public class DatabaseConfig {
  41.  
  42. @Primary
  43. @Bean(name = "dataSource")
  44. @ConfigurationProperties(prefix = "real.datasource")
  45. public DataSource dataSource() {
  46. return DataSourceBuilder.create().build();
  47. }
  48.  
  49. @Primary
  50. @Bean
  51. public LocalContainerEntityManagerFactoryBean realEntityManagerFactory(EntityManagerFactoryBuilder builder) {
  52. LocalContainerEntityManagerFactoryBean emf = builder.dataSource(dataSource())
  53. .packages("com.xxx.xxx")
  54. .persistenceUnit("real")
  55. .build();
  56.  
  57. return emf;
  58. }
  59.  
  60. @Primary
  61. @Bean
  62. public PlatformTransactionManager realTransactionManager(@Qualifier("realEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
  63. return new JpaTransactionManager(entityManagerFactory);
  64. }
  65.  
  66. }
  67.  
  68. real.datasource.jdbc-url=jdbc:oracle:thin:xxxxxxx
  69. real.datasource.username=xxxxx
  70. real.datasource.password=xxxxx
  71. real.datasource.driver-class-name=oracle.jdbc.OracleDriver
  72.  
  73. spring.datasource.jdbc-url=jdbc:mysql://localhost:xxxxx
  74. spring.datasource.username=xxxx
  75. spring.datasource.password=xxxx
  76. spring.jpa.database=default
Add Comment
Please, Sign In to add comment