Connect to Different Types of Databases in Spring Boot
How to Connect to Multiple and Different Database Sources in Your Spring Boot Project
I had described how to connect to different Cassandra database keyspaces in my previous post:
Connect to Different Cassandra Keyspaces in Spring Boot
How to Connect to Multiple Cassandra Keyspaces in Your Spring Boot Project
My project was implemented with Spring Boot 2.3.5 RELEASE.
These were my other dependencies used for database operations implementation:
In addition to those, I had to connect to a MySQL database:
Please pay attention to “basePackages” and “mysqlDbEntityManager” for my MySQL model and repository folder. “persistenceUnit” name should be unique for each configuration in your project.
ConfigurationProperties “prefix” value is the prefix for database connection properties in application.properties file.
#==== MySQL Configuration ======#
I declared this datasource as primary (by adding a “Primary” annotation).
Again, I implemented my model, repository and service classes just like I would in a single keyspace one.
Now we are good to go!