Skip to content

Multiple datasources support [DATAJDBC-321] #544

Open
@spring-projects-issues

Description

@spring-projects-issues

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

spring-projects-issues commented on Dec 27, 2020

@spring-projects-issues
Author

AndreyChukhlebov commented

Jens Schauder  Hello! I understand that the problem is not very common, but are there any improvements planned?)

AndreyChukhlebov

AndreyChukhlebov commented on Jan 25, 2021

@AndreyChukhlebov

problem solution for postgress https://github.com/AndreyChukhlebov/spring-data-mongo-web crutch)

archanamarathe

archanamarathe commented on Jun 21, 2021

@archanamarathe

@AndreyChukhlebov The solution worked perfectly! Thanks much!!!

kota65535

kota65535 commented on Jun 25, 2021

@kota65535

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 and dataAccessStrategyRef params of @EnableJdbcRepositories to specify different dependent beans for repositories of each datasource.
But as for JdbcConverter, which is the dependency of JdbcRepositoryFactoryBean, currently we don't have an option to specify ref like above, and therefore we have to use the single JdbcConverter bean for each repository. Due to this limitation, we cannot use multiple SQL dialects (MySQL, PostgreSQL, Oracle, etc...) at the same time.

SimSonic

SimSonic commented on Jul 5, 2021

@SimSonic

Hi all!

I'm implementing the same solutions from this thread

but experiencing these problems with JdbcRepositoryFactoryBean:

Parameter 0 of method setConverter in org.springframework.data.jdbc.repository.support.JdbcRepositoryFactoryBean required a single bean, but 2 were found:
	- db1JdbcConverter: defined by method 'db1JdbcConverter' in class path resource [.../JdbcDb1Config.class]
	- db2JdbcConverter: defined by method 'db2JdbcConverter' in class path resource [.../JdbcDb2Config.class]

How do you solve this?

Spring Boot 2.5.2. Both datasources to Oracle.

kota65535

kota65535 commented on Jul 5, 2021

@kota65535

Hi @SimSonic, your problem seems to be related to this issue, and you should annotate @Primary to the one of the JdbcConverter bean to specify which one you use like this.

SimSonic

SimSonic commented on Jul 5, 2021

@SimSonic

Hi @SimSonic, your problem seems to be related to this issue, and you should annotate @Primary to the one of the JdbcConverter bean to specify which one you use like this.

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

holmofy commented on Jul 12, 2021

@holmofy

I also encountered this problem. In which version is this problem solved?

ghostGuiggs

ghostGuiggs commented on Nov 2, 2021

@ghostGuiggs

@kota65535 thanks for the repo

10 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @schauder@isimonov@SimSonic@ghostGuiggs@jtkb

    Issue actions

      Multiple datasources support [DATAJDBC-321] · Issue #544 · spring-projects/spring-data-relational