Spring Data JPA - Multiple EnableJpaRepositories

前端 未结 3 619
执笔经年
执笔经年 2020-11-29 21:29

My application has multiple data sources , so i have created two data source configuration classes based on this URL .

But while running the spring boot applicatio

3条回答
  •  野性不改
    2020-11-29 21:37

    The answered provided by @Daniel C. is correct. Small correction/observation from my side.

    • @Primary is not required if you don't want to mark any datasource as default one, otherwise necessary.
    • If you are defining any of the EntityManagerFactoryBean with @Bean name as entityManagerFactory then it's better to mark it @Primary to avoid conflict.
    • @ConfigurationProperties("app.datasource.servers") can be marked at class level instead of defining at method level.
    • Better to return HikariDataSource as datasource if you using Spring Boot 2.x or higher version as it has been changed.
    • Make sure you define exact property for jdbc-url which is being used by HikariDataSource to refer JDBC Connection URL.

提交回复
热议问题