https://github.com/unikueltd/multiple-datasource-spring-boot-starter
Multiple datasource for spring boot starter
https://github.com/unikueltd/multiple-datasource-spring-boot-starter
database datasource spring-boot spring-starter
Last synced: 6 months ago
JSON representation
Multiple datasource for spring boot starter
- Host: GitHub
- URL: https://github.com/unikueltd/multiple-datasource-spring-boot-starter
- Owner: unikueltd
- License: apache-2.0
- Created: 2024-06-29T06:56:04.000Z (about 2 years ago)
- Default Branch: trunk
- Last Pushed: 2025-09-14T13:57:31.000Z (10 months ago)
- Last Synced: 2026-01-11T18:45:22.957Z (6 months ago)
- Topics: database, datasource, spring-boot, spring-starter
- Language: Java
- Homepage: https://mvnrepository.com/artifact/com.yookue.springstarter/multiple-datasource-spring-boot-starter
- Size: 109 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Notice: NOTICE.txt
Awesome Lists containing this project
README
# Multiple Datasource Spring Boot Starter
Spring Boot application integrates multiple `DataSource` quickly.
## Quickstart
- Import dependencies
```xml
cn.unikue.springstarter
multiple-datasource-spring-boot-starter
LATEST
```
> By default, this starter will auto take effect, you can turn it off by `spring.multiple-datasource.enabled = false`
- Configure Spring Boot `application.yml` with prefix `spring.multiple-datasource`
```yml
spring:
multiple-datasource:
primary:
url: 'jdbc:mysql://127.0.0.1:3306/test_db1'
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
jpa-enabled: true
repository-enabled: true
mybatis:
xa:
secondary:
url: 'jdbc:mysql://127.0.0.1:3306/test_db2'
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.mchange.v2.c3p0.ComboPooledDataSource
jpa-enabled: true
repository-enabled: true
mybatis:
xa:
tertiary:
url: 'jdbc:mysql://127.0.0.1:3306/test_db3'
driver-class-name: com.mysql.cj.jdbc.Driver
type: org.apache.commons.dbcp2.BasicDataSource
jpa-enabled: true
repository-enabled: true
mybatis:
xa:
```
> This starter supports 3 `DataSource` at most. (Three strikes and you're out)
- Locate your entities and repositories under the following packages (take `primary` as an example)
- Entities: `**.domain.primary.rdbms`
- Repositories: `**.repository.primary.rdbms`
- Configure your beans with the following beans by `@Autowired`/`@Resource` annotation, combined with `@Qualifier` annotation (take `primary` as an example)
| Bean Type | Qualifier |
|------------------------|------------------------------------------------------------|
| DataSource | PrimaryDataSourceJdbcConfiguration.DATA_SOURCE |
| JdbcTemplate | PrimaryDataSourceJdbcConfiguration.JDBC_TEMPLATE |
| TransactionManager | PrimaryDataSourceJdbcConfiguration.TRANSACTION_MANAGER |
| PersistenceUnitManager | PrimaryDataSourceJpaConfiguration.PERSISTENCE_UNIT |
| EntityManager | PrimaryDataSourceJpaConfiguration.ENTITY_MANAGER |
| SqlSessionFactory | PrimaryDataSourceMybatisConfiguration.SQL_SESSION_FACTORY |
| SqlSessionTemplate | PrimaryDataSourceMybatisConfiguration.SQL_SESSION_TEMPLATE |
- This starter supports the most popular data source pools in the world, including
- c3p0
- dbcp2
- druid
- hikari
- oracle ucp
- tomcat
- vibur
## Document
- Github: https://github.com/unikueltd/multiple-datasource-spring-boot-starter
## Requirement
- jdk 17+
## License
This project is under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)
See the `NOTICE.txt` file for required notices and attributions.
## Donation
You like this package? Then [donate to us](https://unikue.cn/donation) to support the development.
## Copyright
Beijing Unikue Network Technology Ltd.
## Website
- Unikue: https://unikue.cn