Description
Marek Šabo opened DATAJDBC-321 and commented
As mentioned in the SO answer, spring-data-jdbc currently doesn't support multiple datasources.
It would be great to add this support in future releases.
Immediate help for advanced spring users would be making JdbcRepositoryFactoryBean constructor public. That way we could provide our own dependencies based on the context of datasource.
Next step could extending the @EnableJdbcRepositories
annotation with refs/links to dependencies similar way the @EnableJpaRepositories does.
(In our multi-ds JPA project we use similar configuration to one outlined in this article: https://medium.com/@joeclever/using-multiple-datasources-with-spring-boot-and-spring-data-6430b00c02e7)
Affects: 1.1 M1 (Moore), 1.0.4 (Lovelace SR4)
Reference URL: https://stackoverflow.com/a/50197148/303559
Issue Links:
- DATAJDBC-499 Register custom converters in two independent modules
("is duplicated by") - DATAJDBC-622 Add support for transactionManagerRef in EnableJdbcRepository
14 votes, 15 watchers
Activity
spring-projects-issues commentedon Dec 27, 2020
AndreyChukhlebov commented
Jens Schauder Hello! I understand that the problem is not very common, but are there any improvements planned?)
AndreyChukhlebov commentedon Jan 25, 2021
problem solution for postgress https://github.com/AndreyChukhlebov/spring-data-mongo-web crutch)
archanamarathe commentedon Jun 21, 2021
@AndreyChukhlebov The solution worked perfectly! Thanks much!!!
kota65535 commentedon Jun 25, 2021
Thanks to @AndreyChukhlebov, I've created an example for multiple RDB (MySQL & PostgreSQL) repositories.
https://github.com/kota65535/spring-data-jdbc-multi-repos
We can use
jdbcOperationsRef
,transactionManagerRef
anddataAccessStrategyRef
params of@EnableJdbcRepositories
to specify different dependent beans for repositories of each datasource.But as for
JdbcConverter
, which is the dependency ofJdbcRepositoryFactoryBean
, currently we don't have an option to specify ref like above, and therefore we have to use the singleJdbcConverter
bean for each repository. Due to this limitation, we cannot use multiple SQL dialects (MySQL, PostgreSQL, Oracle, etc...) at the same time.SimSonic commentedon Jul 5, 2021
Hi all!
I'm implementing the same solutions from this thread
but experiencing these problems with
JdbcRepositoryFactoryBean
:How do you solve this?
Spring Boot 2.5.2. Both datasources to Oracle.
kota65535 commentedon Jul 5, 2021
Hi @SimSonic, your problem seems to be related to this issue, and you should annotate
@Primary
to the one of theJdbcConverter
bean to specify which one you use like this.SimSonic commentedon Jul 5, 2021
Thanks a lot. I've found both of my configurations were extending AbstractJdbcConfiguration. Removed that and marked some of beans
@Primary
and it started to work.holmofy commentedon Jul 12, 2021
I also encountered this problem. In which version is this problem solved?
ghostGuiggs commentedon Nov 2, 2021
@kota65535 thanks for the repo
10 remaining items