'Struggling to switch between databases at runtime with Spring boot
I'm trying to change which database is used at runtime (like from H2 to MySQL and back). Is it also possible to make both of them be used simultaneously (meaning whatever data is saved in both databases, whenever a repository is saved to use what appears to be the correct terminology or at least the convention)?
I tried so many different things, but my knowledge of Spring Boot is very limited.
My attempts all revolved around trying to change spring.profiles.active=h2
to spring.profiles.active=mysql
and vice versa, as in what's in the application.properties
file, but within the code.
I'm not necessarily looking for a way that's similar to what I've been trying.
Could someone please help me figure out how to do this?
Any input would be GREATLY appreciated!
P.S. For what it's worth, the code I'm working with is here ( https://github.com/spring-projects/spring-petclinic ).
Solution 1:[1]
I would suggest you to check Spring Cloud config, it is the mechanism to configure your app at run time. https://cloud.spring.io/spring-cloud-config/reference/html/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Saurabh Singh |