This is a good example elaborating multi-tenancy and AbstractRoutingDataSource usage, however it requires pre-defined data sources you cannot add runtime datasources.
Run the following command to build the solution:
mvn clean compile package
You're going to need a database which has a structure like this:
CREATE TABLE orders (
id int not null auto_increment,
date datetime not null,
primary key(id)
);
Create a new database per tenant and include a new properties file in the tenants folder in the root of the solution. The contents of this file looks like this:
name=<tenant id>
datasource.url=jdbc:mysql://localhost:3306/<tenant>
datasource.username=
datasource.password=
Next boot up the application using the following command and try it out using SOAPUI, Postman or Curl.
java -jar target/demo-0.0.1-SNAPSHOT.jar
Enjoy!