com.alibaba.druid.spring.boot.ds.DynamicDataSource Maven / Gradle / Ivy
package com.alibaba.druid.spring.boot.ds;
import java.lang.reflect.Field;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import org.springframework.util.ReflectionUtils;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.DruidProperties;
import com.alibaba.druid.spring.boot.util.DruidDataSourceUtils;
@SuppressWarnings("unchecked")
public class DynamicDataSource extends AbstractRoutingDataSource {
protected static Field targetDataSourcesField = ReflectionUtils.findField(DynamicDataSource.class,
"targetDataSources");
protected static Field resolvedDataSourcesField = ReflectionUtils.findField(DynamicDataSource.class,
"resolvedDataSources");
@Override
protected Object determineCurrentLookupKey() {
return DataSourceContextHolder.getDatabaseName();
}
public Map