Why not use Spring Profiles instead of configuring both database connections in a single application.yml file? You can create separate application.yml files for each profile and assign each profile to a different database connection.
By using profiles, you can easily manage different environments (e.g., development, testing, production) with their respective configurations. For example:
Create separate configuration files for each environment:
application-dev.yml for development application-prod.yml for production Activate the profile you need in your main application.yml or as a command-line argument when running your application.
Example: application.yml:
yaml spring: profiles: active: dev application-dev.yml:
yaml spring: datasource: url: jdbc:postgresql://localhost:5432/dev_db username: dev_user password: dev_password application-prod.yml:
yaml spring: datasource: url: jdbc:postgresql://localhost:5432/prod_db username: prod_user password: prod_password This way, you can cleanly separate your database configurations for each profile without cluttering a single file.