This post is an update from the original post created the 22nd of Nov 2015.
In this example we will see how to config two datasources on different environments (development, test, production)
using a YAML config file. Before starting, I added in my pom.xml the spring-boot-starter-jdbc.
application.yml
In order to represent the several environments I used profiles. After that, for each environment I set the properties concerning the datasources. We can
notice the two datasources each time.
Profiles are used to group beans together. For a specific profile the beans are created only if the profile is activated.
Application.groovy
Usually, Spring boot creates automatically a datasource and a jdbcTemplate when the jdbc-starter is part of the dependencies.
Behind the scene, it checks in classpath for libraries brought by the starters, based on the presence of certain libraries it will autoconfigure beans.
Spring boot is said as opinionated. Also, it is worth mentioning that Spring Boot reads the application properties to auto-configure the beans. This is how Spring Boot
can create a datasource, but you have to respect the right names for the properties.
In the case of multiple datasources Spring Boot can’t guess that you actually want multiple datasources. Hopefully, it’s possible to override Spring Boot behaviour and
define these beans ourself.