0
votes

I am working on developing a multi-tenant application using spring boot.

The business logic of the system will change on a per-tenant basis.

For example, a specific tenant leasing space on the application may want to change the way a value is calculated using some complex custom logic. I would like to register a default behavior/dependency for an application and allow a specific tenant to override it.

Can this be done using Spring Boot ?

2
Yes. Yes it can. - mypetlion

2 Answers

0
votes

This question is very vague. But I try to provide a few pointers. There seem to be two different problems to solve:

  1. you need to have dynamically loadable parts of business logic. These parts need to come from tenant-specific storage, like file system or database. A simple way to approach this could be the Java ScriptEngine, that could load a calculation/logic script and execute it. A more comprehensive approach is a business rule engine. There are several, some with spring integration, you can google for them to find resources.

  2. You need tenant-aware data access, most probably database access. This includes

    • discriminating the data by tenant, e.g. by using a separate database (scheme) per tenant, or a column in each table where the tenant identifier is stored. Spring does not directly support this, but the underlying technology (like e.g. a JPA implementation) might. My company implemented s.th. like this internally for MongoDB, it was not as hard as it might sound.
    • a way to determine to which tenant an action belongs. For web/webservice applications the tenant is usually supplied as part of the host name, the URL path or as a custom HTTP header. There was a plan to standardize this for Servlet 4.0, but as far as I know it eventually didn't make it into the spec. So you are on your own, but it really isn't hard to implement.

So to summarize: Spring (Boot) does not directly help much with it, but with the pointers above you can start to look into implementing it yourself while using Spring Boot.

0
votes

Check this out:

https://github.com/singram/spring-boot-multitenant

I think if you are using spring boot, it might be a web app. So carry the Tenant-ID with http/header, and you can use different data source.

Logic wise, you can differentiate you tenant by RestController address or Tenant-ID carry in header/body/url