Git Product home page Git Product logo

spring-boot-multitenant's Introduction

spring-boot-multitenant

Multi tenancy example using spring boot and the Hibernate SCHEMA strategy.

Getting started

Pre-requisites

  • Java 1.8
  • Docker
  • Docker-compose

Installation (debian base)

Install Docker

apt-get install apparmor lxc cgroup-lite
wget -qO- https://get.docker.com/ | sh
sudo usermod -aG docker YourUserNameHere
sudo service docker restart

Install Docker-compose (1.6+)

MAKE SURE YOU HAVE AN UP TO DATE VERSION OF DOCKER COMPOSE

To check the version:

docker-compose --version

To install the 1.6.0:

sudo su
curl -L https://github.com/docker/compose/releases/download/1.6.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
exit

To run

docker-compose up

To run docker mysql while running app locally

docker-compose up mysql
./gradlew bootRun

Usage

Prime the database (only needs to be done once)

docker-compose up mysql
mysql -u root   -p1234   -h 127.0.0.1 -e "GRANT ALL ON *.* TO 'myuser'@'%'; FLUSH PRIVILEGES;"
mysql -u myuser -pmypass -h 127.0.0.1 < db_migration.sql

At this point there should be two identical databases tenant_a and tenant_b with privileges such that the myuser account can access both

Start the app

./gradlew clean build buildDocker
docker-compose up api

API interactions

curl -H "X-TenantID:tenant_a" localhost:8080/person/1
curl -i -X POST -H "X-TenantID:tenant_a" -H "Content-Type:application/json" -d '{ "firstName" : "Frodo", "lastName" : "Baggins" }' http://localhost:8080/person/

spring-boot-multitenant's People

Contributors

singram avatar

Watchers

James Cloos avatar Satish Kotadiya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.