I think this is the starter I miss the most in this near perfect framework. It should be an autconfiguration for multitenant setups, which nicely integrates with spring-data (for datasource resolution), spring-oauth2-resource-server (since tenantId could come from a token jwt claim), and spring-logging (for contextualization of tenant as an MDC property). I guess a custom centralized service would still be needed to store all tenant informations, but it still would speed up a lot this typical need
Just a proposal :)
Comment From: wilkinsona
Thanks for the suggestion, but I don't think that multi-tenancy is something that Spring Boot can have a strong enough opinion about to warrant having an auto-configuration and a starter for it. For example, there's no guarantee that a multi-tenant application will be using a DataSource or that it will be using OAuth. I think there are just too many variables around each individual application's approach to multi-tenancy for Boot to do anything meaningful. Thanks again for the suggestion though.
Comment From: nightswimmings
@wilkinsona Perhaps narrowing it down to a cool abstraction for datasource proxying in spring-data (jpa/mongo etc..) would be more resonable and maybe not callign it spring-boot-multitenancy but spring-boot-data-multitenancy?
Comment From: wilkinsona
If you haven't already seen them, you may want to look at Spring Framework's AbstractRoutingDataSource
(JDBC) and AbstractRoutingConnectionFactory
(R2DBC). I'm not aware of equivalents for the NoSQL data stores supported by Spring Data. You could raise that with the Data team on Gitter.
I still don't see any scope for Spring Boot auto-configuring anything at this point. We'd like to offer support for auto-configuring multiple DataSource
beans and the like (https://github.com/spring-projects/spring-boot/issues/15732). That change may then given us something upon which we could build auto-configuration for AbstractRoutingDataSource
and the like, but that would almost certainly need to be something that you opt into as not every application with multiple data sources will be a multi-tenant application.
Comment From: nightswimmings
Amazing thanks!