com.raufferlobo.springboot.multitenant.mongodb:spring-boot-multitenant-mongodb

An useful Mongodb factory which allows applications to choose the database name at runtime.

Лицензия

Лицензия

Категории

Категории

Spring Boot Контейнер Микросервисы Ant Компиляция и сборка MongoDB Данные Базы данных
Группа

Группа

com.raufferlobo.springboot.multitenant.mongodb
Идентификатор

Идентификатор

spring-boot-multitenant-mongodb
Последняя версия

Последняя версия

1.0.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

An useful Mongodb factory which allows applications to choose the database name at runtime.
Организация-разработчик

Организация-разработчик

Pivotal Software, Inc.
Система контроля версий

Система контроля версий

http://github.com/rauffer/spring-boot-multitenant-mongodb/tree/master

Скачать spring-boot-multitenant-mongodb

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.raufferlobo.springboot.multitenant.mongodb/spring-boot-multitenant-mongodb/ -->
<dependency>
    <groupId>com.raufferlobo.springboot.multitenant.mongodb</groupId>
    <artifactId>spring-boot-multitenant-mongodb</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.raufferlobo.springboot.multitenant.mongodb/spring-boot-multitenant-mongodb/
implementation 'com.raufferlobo.springboot.multitenant.mongodb:spring-boot-multitenant-mongodb:1.0.2'
// https://jarcasting.com/artifacts/com.raufferlobo.springboot.multitenant.mongodb/spring-boot-multitenant-mongodb/
implementation ("com.raufferlobo.springboot.multitenant.mongodb:spring-boot-multitenant-mongodb:1.0.2")
'com.raufferlobo.springboot.multitenant.mongodb:spring-boot-multitenant-mongodb:jar:1.0.2'
<dependency org="com.raufferlobo.springboot.multitenant.mongodb" name="spring-boot-multitenant-mongodb" rev="1.0.2">
  <artifact name="spring-boot-multitenant-mongodb" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.raufferlobo.springboot.multitenant.mongodb', module='spring-boot-multitenant-mongodb', version='1.0.2')
)
libraryDependencies += "com.raufferlobo.springboot.multitenant.mongodb" % "spring-boot-multitenant-mongodb" % "1.0.2"
[com.raufferlobo.springboot.multitenant.mongodb/spring-boot-multitenant-mongodb "1.0.2"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-data-mongodb jar 1.5.9.RELEASE

provided (1)

Идентификатор библиотеки Тип Версия
javax.servlet : javax.servlet-api jar 3.1.0

test (3)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-test jar 1.5.9.RELEASE
de.flapdoodle.embed : de.flapdoodle.embed.mongo jar 1.50.5
org.mockito : mockito-core jar 1.10.19

Модули Проекта

Данный проект не имеет модулей.

spring-boot-multitenant-mongodb

This project contains a spring-data-mongodb factory extension which is responsible to choose the database name at runtime.

For each request made by a user, Spring data asks the mongodb factory which database may use. This extension uses a TenantProvider interface to decide the database name at runtime.

Setting up your application

Add the Maven dependency:

<dependency>
	<groupId>com.raufferlobo.springboot.multitenant.mongodb</groupId>
	<artifactId>spring-boot-multitenant-mongodb</artifactId>
	<version>1.0.2</version>
</dependency>

Enable Spring boot auto configuration using the@EnableAutoConfiguration annotation:

@SpringBootApplication
@EnableAutoConfiguration
public class SampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }
    
}

Create a TenantProvider implementation:

@Component
public class MyTenantResolver implements TenantResolver {

    @Override
    public String resolve(HttpServletRequest request) {
        return request.getHeader("X-Tenant"); // implement your own strategy
    }

}

Default behavior

Considering the following application.properties file:

spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=sample

The default database name is sample, so if the TenantProvider implementation returns tenant1 as result, the MultitenantMongoDbFactory will consider the database name as sample-tenant1.

You can also override the database prefix by providing a tenant prefix as a property:

spring.data.mongodb.tenant-prefix=my-prefix

When MultitenantMongoDbFactory finds this property, the result is my-prefix-tenant1 instead of sample-tenant1.

If you don't provide a TenantProvider implementation or if your TenantProvider return null, the factory will assume the default database name ("sample" in the previous example).

Версии библиотеки

Версия
1.0.2