package com.changhong.epc.config.datasource; import com.alibaba.druid.pool.DruidDataSource; import com.changhong.epc.constter.system.DataSourceKey; import com.iemsoft.framework.cloud.config.datasource.AbstractDataSourceConfig; import com.iemsoft.framework.cloud.config.datasource.DataSourceInfo; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.HashMap; import java.util.Map; /** * 数据源配置 * @author WangYX * */ @Configuration public class DataSourceConfig extends AbstractDataSourceConfig implements DataSourceKey{ /** * 数据源info */ @Override protected DataSourceInfo getDataSourceInfo() { Map dsMap = new HashMap<>(); dsMap.put(TENANT_DATA_1_SOURCE, tenant1DataSource()); // 租户1 dsMap.put(TENANT_DATA_2_SOURCE, tenant2DataSource()); // 租户2 dsMap.put(ADMIN_DATA_SOURCE , centerDataSource()); // 管理中心 return new DataSourceInfo(dsMap, TENANT_DATA_1_SOURCE); } /** * 管理中心数据源 * @return */ @Bean(initMethod="init",destroyMethod="close") @ConfigurationProperties(prefix="spring.datasource.center") protected DruidDataSource centerDataSource() { return new DruidDataSource(); } /** * 租户1库数据源 * @return */ @Bean(initMethod="init",destroyMethod="close") @ConfigurationProperties(prefix="spring.datasource.tenant1") protected DruidDataSource tenant1DataSource() { return new DruidDataSource(); } /** * 租户2库数据源 * @return */ @Bean(initMethod="init",destroyMethod="close") @ConfigurationProperties(prefix="spring.datasource.tenant2") protected DruidDataSource tenant2DataSource() { return new DruidDataSource(); } }