Category Archives: MultiTenant

Creating a Multi-Tenant Web App with Grails

The grails multi-tenant plugin allows you to run multiple “customers” (or tenants) from one installation of a grails application with minimum configuration. Application developers who would normally have to install multiple instance of their grails app (one-per-customer) and maintain multiple databases (one-per-customer) can use this plugin to run multiple customers from the same application AND database. The plugin also supports a single-tenant database configuration (one webapp for all tenants, but a datasource for each tenant).

Installation :

For installing run command,


 grails install-plugin multi-tenant

Webapp always runs in multi-tenant mode. But you can configure singleTenant  also. In your config.groovy add following,

tenant {
         mode = “singleTenant” // OR “multiTenant”

By default its multiTenant.

MultiTenant database set-up:

The ‘multiTenant’ mode relies your application to use just one database for all tenants running. For this firstly, you will need to specify which classes you want to make multitenant.  You can do this by annotating your class with @MultiTenant annotation. As shown below:

import grails.plugin.multitenant.core.groovy.compiler.MultiTenant
class MyClass {


Integer tenantId() {   //Defining indexes inside Grails domain classes

This way, each instance of MyClass will belong to some tenant and all hibernate events that query your database, will add another condition in your queries that will filter just instances of the current tenant.


ProsperaSoft offers Grails development solutions. You can email at to get in touch with ProsperaSoft Grails experts and consultants.