routing-data-source | using Spring RoutingDataSource and custom annotations | Build Tool library
kandi X-RAY | routing-data-source Summary
kandi X-RAY | routing-data-source Summary
Example of using Spring RoutingDataSource and custom annotations to determine concrete DataSource
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Test
- Test master update
- Test database
- Test replica
- Get the current database type
- Annotation point
- Sets the DB type
- Clear database type
- Handles a writeConnection
- Determines the current lookup key
routing-data-source Key Features
routing-data-source Examples and Code Snippets
Community Discussions
Trending Discussions on routing-data-source
QUESTION
Hi everyone I've follow this guide to realize a Multi-tenant application with Spring-Boot:
https://www.baeldung.com/spring-abstract-routing-data-source
Everything works fine, I use an interceptor to intercept http request and based on my business logic set tanant_A or tenant_B. In my use case I have only one scenario, where I have to set tenant_A, persist data on this DataSource in a Transaction, and after that I have to persist the same data on tenant B using the same Entities and Repositories (tenant_B is a REPLICA of tenant_A).
Example my REST controller:
...ANSWER
Answered 2018-Dec-04 at 16:05The problem is with my Repository Class:
QUESTION
I'm getting an issue with Spring framework while I try to connect to 2 identical databases (with same tables) and then choose one of them to make requests. I'm using for this, 3 config files DbConfig, AbstractRoutingDataSource and an application.properties file. I'm currently not getting any ERRORS, while starting my application, but any time I use my restful webservice I get empty data, check the controller file below.
NOTE: I've followed all these links and still no results:
- Baeldung AbstractRoutingDataSource guide
- Alexander guide
- Dynamic DataSource Routing on Spring website
I'm working on Spring boot v2.0.5.
NOTE: please do NOT answer me if you don't have any ideas about AbstractRoutingDataSource class and how it works.
My application.properties file ...ANSWER
Answered 2018-Dec-06 at 11:52Well I found the solution! The problem was simply with my .properties and my DbConfig files. I just omitted databases parameters from .properties file and added them manually to my DbConfig file. and it works fine:
My Properties fileQUESTION
In our application, we have a common database called central
and every customer will have their own database with exactly the same set of tables. Each customer's database might be hosted on our own server or the customer's server based on the requirement of the customer organization.
To handle this multi-tenant requirement, we're extending the AbstractRoutingDataSource
from Spring JPA and overriding the determineTargetDataSource()
method to create a new DataSource
and establish a new connection on the fly based on the incoming customerCode
. We also use a simple DatabaseContextHolder
class to store the current datasource context in a ThreadLocal
variable. Our solution is similar to what is describe in this article.
Let's say in a single request, we'll need to update some data in both the central
database and the customer's database as following.
ANSWER
Answered 2018-Dec-13 at 10:32We found a working solution, which is a mix of static data source settings for our central
database and dynamic data source settings for our customer's database.
In essence, we know exactly which table comes from which database. Hence, we were able to separate our @Entity
classes into 2 different packages as following.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install routing-data-source
You can use routing-data-source like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the routing-data-source component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page