@Component
public class MultiDataSource extends AbstractRoutingDataSource {
@Autowired
private Dydatasource dydatasource;
private static final ThreadLocal<String> dataSourceKey = new InheritableThreadLocal<String>();
/**
* 设置dataSourceKey的值
* @param dataSource
*/
public void setDataSourceKey(String dataSource) throws SQLException {
{
System.out.println(22222);
System.out.println(dataSource);
// String conf = "applicationContext.xml";
// ApplicationContext ac = new ClassPathXmlApplicationContext(conf);
// Dydatasource dydatasource = ac.getBean("dydatasource", Dydatasource.class);
DataSource turedatasource = dydatasource.registerDs(dataSource);
System.out.println(dydatasource);
Object ture = turedatasource;
Object data = dataSource;
System.out.println(2);
Map<Object, Object> objectObjectMap = new HashMap<Object, Object>();
objectObjectMap.put(data, ture);
super.setTargetDataSources(objectObjectMap);
System.out.println(objectObjectMap.get(data));
// dataSourceKey.set(dataSource);
}
}
/**+
* 清除dataSourceKey的值
*/
public static void toDefault() {
// dataSourceKey.remove();
}
/**
* 返回当前dataSourceKey的值
*/
@Override
protected Object determineCurrentLookupKey() {
// return dataSourceKey.get();
return null;
}
}
慕虎7371278