Open waffel opened 9 years ago
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.
Example is here https://github.com/eepstein/multids-demo
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.
The documentation has also been updated as well.
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
@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.
thanks :+1:
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.
follow the comments from https://github.com/mybatis/spring-boot-starter/issues/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.
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
@kcmvp please do not hijack this issue to ask questions. We use StackOverflow or Gitter for that.
Is this issue still open?
@rahul404 there is an open
label at the top of this page. Yes it is still open.
Can i work on it?
@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.
See also #14928
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.
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:
data-${platform}.sql
files to add data to two different test databasesCrudRepository
interfaceI 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.