com.feingto.cloud.config.datasource.dynamic.EnableDynamicDataSource Maven / Gradle / Ivy
The newest version!
package com.feingto.cloud.config.datasource.dynamic;
import com.feingto.cloud.config.datasource.dynamic.support.DataSourceAutoConfiguration;
import com.feingto.cloud.config.datasource.dynamic.support.DataSourceRegister;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
// @formatter:off
/**
* 注解启用动态数据源 @EnableDynamicDataSource
* 事务方法上使用@DataSource("ds1")来切换数据源
*
* 配置文件 application.yml
* spring:
* datasource: # 主数据源
* master-slave:
* enabled: true # 主从读写分离
* driver-class-name: com.mysql.cj.jdbc.Driver
* type: com.zaxxer.hikari.HikariDataSource
* url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8
* username: root
* password: root
* multi-datasource: # 更多数据源(name以"slave-"为前缀的自动作为从数据源,遵循读写分离机制)
* names: ds1, ds2, slave-ds1
* ds1:
* url: jdbc:mysql://localhost:3306/test1?characterEncoding=utf-8
* username: root
* password: root
* ds2:
* driver-class-name: oracle.jdbc.OracleDriver
* url: jdbc:oracle:thin:@localhost:1521:orcl
* username: root
* password: root
* slave-ds1:
* url: jdbc:mysql://localhost:3306/test1?characterEncoding=utf-8
* username: root
* password: root
*
* @author longfei
*/
// @formatter:on
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import({DataSourceAutoConfiguration.class, DataSourceRegister.class})
public @interface EnableDynamicDataSource {
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy