Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation showing how to use two different databases #3456

Open
waffel opened this issue Jul 10, 2015 · 16 comments
Open

Improve documentation showing how to use two different databases #3456

waffel opened this issue Jul 10, 2015 · 16 comments
Labels
type: documentation A documentation update
Milestone

Comments

@waffel
Copy link

waffel commented Jul 10, 2015

It would be nice to get a working example, how to use and configure two databases in spring boot.

The documentation says, that it is only required to create a datasource configuration with two different datasources.

But this does not work complete. The example application can show how to:

  • define and use different data-${platform}.sql files to add data to two different test databases
  • use the datasources in repositories where we define simple an interface which extends from the CrudRepository interface
  • create a test case where data will be written into one datasource and read from another and then mix the result into a controller to deliver both data (via REST for example) to the client

I have not found any "complete" example for this. But it is mentioned in the documentation, that this is easy and supported by spring-boot .. so it would be nice to have such example.

@jamesbehrens1
Copy link

It would be interesting to see what is recommended for multiple databases. I have a multi-tenant solution that I have cobbled together and don't specifically trust. I know that I have memory leaks and presume that it is because I have deviated from the spring boot way. I have six jdbc bean pools configured and determine which one to inject into the service based on the restful call. This solution leaves me tightly bound to JTDS for a JDBC driver and, as mentioned above, I am trying to sort out memory leaks.
image

@eepstein
Copy link

eepstein commented Aug 5, 2015

@snicoll
Copy link
Member

snicoll commented Jan 23, 2017

There is also https://github.com/snicoll-demos/demo-multi-entity-managers that is meant to demonstrate the JPA/Spring Data use case with two datasources and Spring Boot.

@snicoll
Copy link
Member

snicoll commented Mar 22, 2018

The documentation has also been updated as well.

@snicoll snicoll closed this as completed Mar 22, 2018
@snicoll snicoll added status: duplicate A duplicate of another issue and removed type: enhancement A general enhancement labels Mar 22, 2018
@waffel
Copy link
Author

waffel commented Apr 4, 2018

Can we reopen this issue? The example from https://github.com/snicoll-demos/demo-multi-entity-managers is really helpful for spring-boot 1.x

But the documentation for spring-boot 2.x does not tell us about how to separate (or setup) domain objects/packages to specific datasource (is we have more than one).

It also unclear how to setup special hibernate properties (for example) for each datasource and how a test can look (with a database auto creation and sql import like the "import.sql" feature worked for 1.x).

The mentioned example https://github.com/eepstein/multids-demo does no longer exists.

I would like to help to create a spring-boot 2.x example if somebody can help me to figure out how to do this. So I can start with a example repo (which I have already on my local) where at the end the tests are failing because of some missing peaces.

Thanks in advance

@philwebb philwebb reopened this Apr 4, 2018
@philwebb philwebb changed the title provide spring-boot-example to show how to use two different databases Improve documenbtation showing how to use two different databases Apr 4, 2018
@philwebb philwebb added type: documentation A documentation update status: ideal-for-contribution An issue that a contributor can help us with and removed status: duplicate A duplicate of another issue labels Apr 4, 2018
@philwebb philwebb added this to the Icebox milestone Apr 4, 2018
@philwebb
Copy link
Member

philwebb commented Apr 4, 2018

@waffel I've re-opened the issue but it might take a while for us to get to this. Feel free to share the sample that you have created so far.

@bclozel bclozel changed the title Improve documenbtation showing how to use two different databases Improve documentation showing how to use two different databases Apr 4, 2018
@waffel
Copy link
Author

waffel commented Apr 11, 2018

thanks 👍

I have managed to get it work with spring boot 2.0.1 .. I will start to create a demo repo and link it here .. there are some open topics which we can discuss on the demo repo or here.

@kcmvp
Copy link

kcmvp commented Apr 12, 2018

follow the comments from mybatis/spring-boot-starter#78, I set it up successfully, but I run into the issue database initialize. when there is just one datasource it works well. but when there are two database, springboot does not pick up the schema-{platform}.sql. In my case it does not pick up schema-h2.sql. but if I rename schema-h2.sql to schema.sql. then it can load.

@kcmvp
Copy link

kcmvp commented Apr 12, 2018

sdk.datasource.jdbc-url=jdbc:h2:mem:sdk
sdk.datasource.username=sa
sdk.datasource.password=
sdk.datasource.driver-class-name=org.h2.Driver
sdk.datasource.initialize=true
sdk.datasource.platform=h2


app.datasource.driver-class-name=com.mysql.jdbc.Driver
app.datasource.initialize=true
app.datasource.platform=mysql
app.datasource.testWhileIdle = true
app.datasource.timeBetweenEvictionRunsMillis = 3600000
app.datasource.validationQuery = SELECT 1

and I have schema-h2.sql and schema-mysql.sql files in classpath

@snicoll
Copy link
Member

snicoll commented Apr 12, 2018

@kcmvp please do not hijack this issue to ask questions. We use StackOverflow or Gitter for that.

@rahul404

This comment has been minimized.

@snicoll

This comment has been minimized.

@rahul404
Copy link
Contributor

Can i work on it?

@snicoll
Copy link
Member

snicoll commented Nov 16, 2018

@rahul404 In retrospects, I am not sure why it was flagged ideal for contribution. It looks like upgrading my sample to SB 2 would already be a good way forward but given the feedback we got so far, I think it should be more prominent than its current location.

@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Nov 16, 2018
@snicoll
Copy link
Member

snicoll commented Nov 16, 2018

See also #14928

@philwebb philwebb removed status: ideal-for-contribution An issue that a contributor can help us with for: team-attention An issue we'd like other members of the team to review labels Nov 16, 2018
@philwebb philwebb modified the milestones: General Backlog, 2.1.x, 2.2.x Nov 16, 2018
@snicoll snicoll self-assigned this Nov 16, 2018
@snicoll snicoll modified the milestones: 2.2.x, 2.x May 17, 2019
@snicoll
Copy link
Member

snicoll commented May 17, 2019

We think that a guide would be a better way to describe how to proceed with this. We'll upgrade the current sample and move it to a guide.

@snicoll snicoll removed their assignment Apr 19, 2021
@philwebb philwebb modified the milestones: 2.x, 3.x Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

7 participants