kwon37xi / replication-datasource-boot

Replication Datasource example for Spring Boot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replication DataSource for Spring Boot 2

You will see how to route database connections to the master DB and the slave DBs with Spring's @Transactional(readOnly=true|false) in this example code.

You can find the basic idea of replication routing datasource in Java (Spring & Non Spring) replication-datasource project.

This is an example for Spring Boot 2 with LazyConnectionDataSourceProxy + AbstractRoutingDataSource.

Configuration for Spring boot 2

Refer to the following 3 source codes.

How to run

Run the following shell command.

./gradlew bootRun

then, you will see the results like the following

# with @Transactional(readOnly = true) method
▶ INFO ### findByIdRead : read_1

# with @Transactional(readOnly = false) method
▶ INFO ### findByIdWrite : write_1

About

Replication Datasource example for Spring Boot

License:Apache License 2.0


Languages

Language:Java 100.0%