- Overview
- 用于在多数据源之间切换
- 依赖SpringBoot环境
- Usage
- 使用maven依赖该项目
<dependency> <groupId>com.spring</groupId> <artifactId>multi-datasource</artifactId> <version>1.0.0</version> </dependency>
- 在application.properties/yml中配置多个数据源,以及其数据源name
#datasource-datasource config spring.datasource.multi.data-source-properties-list[0].data-source-name=datasource1 spring.datasource.multi.data-source-properties-list[0].driver-class-name=com.mysql.jdbc.Driver spring.datasource.multi.data-source-properties-list[0].url=jdbc:mysql://localhost:3306/demo spring.datasource.multi.data-source-properties-list[0].username=xxx spring.datasource.multi.data-source-properties-list[0].password=yyy spring.datasource.multi.data-source-properties-list[0].initial-size=5 spring.datasource.multi.data-source-properties-list[0].max-active=10 spring.datasource.multi.data-source-properties-list[0].min-idle=1 spring.datasource.multi.data-source-properties-list[1].data-source-name=datasource2 spring.datasource.multi.data-source-properties-list[1].driver-class-name=com.mysql.jdbc.Driver spring.datasource.multi.data-source-properties-list[1].url=jdbc:mysql://127.0.0.1:3306/test spring.datasource.multi.data-source-properties-list[1].username=xxx spring.datasource.multi.data-source-properties-list[1].password=yyy spring.datasource.multi.data-source-properties-list[1].initial-size=5 spring.datasource.multi.data-source-properties-list[1].max-active=10 spring.datasource.multi.data-source-properties-list[1].min-idle=1
- 在 Bean (必须实现了接口) 上使用
@SwitchDataSource("datasourceName")
来切换到已配置的某个数据源
@SwitchDataSource("datasource1") public class UserServiceImpl implements UserService { }
-
Notifications
You must be signed in to change notification settings - Fork 1
vinny-constantine/multi-datasource
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
multi-datasource for spring-boot
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published