An open API service indexing awesome lists of open source software.

https://github.com/kasramp/spring-multiple-datasources

Spring example written in Kotlin demonstrates how to use mutiple datasources with the ability of creating tables of the datasources
https://github.com/kasramp/spring-multiple-datasources

hibernate-multitenant jpa jpa-hibernate kotlin kotlin-spring-boot spring-boot spring-boot-3 springboot3

Last synced: 2 months ago
JSON representation

Spring example written in Kotlin demonstrates how to use mutiple datasources with the ability of creating tables of the datasources

Awesome Lists containing this project

README

        

# Spring Boot multiple datasources

An example of Spring Boot, written in Kotlin, demonstrates how to use Hibernate with Kotlin as well as multiple datasources with the ability to create tables of the datasources and support for distributed transactions in multiple datasources.

To understand more about the project read the following tutorials,

- [How to deal with Hibernate entities in Kotlin](https://www.geekyhacker.com/how-to-deal-with-hibernate-entities-in-kotlin/)
- [Spring Boot connect to multiple datasources](https://www.geekyhacker.com/spring-boot-connect-to-multiple-datasources/)
- [Spring transaction with multiple datasources](https://www.geekyhacker.com/spring-transaction-with-multiple-datasources/)
- [PostgreSQL integration tests using Testcontainers](https://www.geekyhacker.com/postgresql-integration-tests-using-testcontainers/)

## How to run

First, start the databases (MySQL 8 and PostgreSQL 15) with `docker-compose`,

```bash
$ docker-compose up -d
```

Then run the project using `mvnw`,

```bash
$ ./mvnw spring-boot:run -Dserver.port=8090
```

Lastly, open the browser and type `http://localhost:8080/swagger-ui/index.html`. You should see the Swagger interface to interact with the API.

## Tips

To change the database configuration modify `docker-compose.yml` and if necessary `application.properties`.