import java.util.HashMap;
import java.util.Map;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
public class DynamicDataSource extends AbstractRoutingDataSource {
public static ThreadLocal<String> key = new ThreadLocal<String>();
private Map<Object, Object> copyTargets = new HashMap<Object, Object>();
@Override
protected Object determineCurrentLookupKey() {
return key.get();
}
public void setCopyTargets(Map<Object, Object> copyTargets) {
this.copyTargets = copyTargets;
setTargetDataSources(copyTargets);
afterPropertiesSet();
}
public Map<Object, Object> getCopyTargets() {
return copyTargets;
}
}
多数据源之动态数据源
最新推荐文章于 2024-05-10 10:01:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)