Skip to main content
Version: 4.6

Advanced Usage

This chapter covers the runtime capabilities that go beyond "switching databases with @DS". Ordered by how often they are used:

TopicDescription
Adding/removing datasources at runtimeadd and remove datasources while running — the foundation of multi-tenant systems
Operations endpoint and metricsan Actuator endpoint listing datasources and groups, plus connection pool Micrometer metrics
Graceful shutdownwait for active connections before closing, avoiding request failures during a release
Dynamic datasource resolutiondecide which database to use from header / session / SpEL
Database password encryptionENC(...) for url / username / password
Startup init scriptsrun schema and data scripts per database
Lazy datasource startupcreate the connection pool only on first use
Startup without datasourcesstart with no datasource configured at all, adding them later
Manual datasource switchingswitch by hand with the toolkit when annotations do not cover the case
Manual multi-datasource injectionwhat to do when you need to own the DataSource bean yourself
Multi-tenancy in practicefour progressively stricter isolation models

Want to drop annotations entirely? See the no-annotation approach.