使用注解,spring中无法注入bean? 5
@ComponentpublicclassMultiDataSourceextendsAbstractRoutingDataSource{@Autowiredprivat...
@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;
}
} 展开
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;
}
} 展开
2个回答
浙江启扬智能科技有限公司
2023-06-12 广告
2023-06-12 广告
Linux 嵌入式系统中,USB 启动模式能够烧写 ARM 的 uboot 的原因主要有以下几个方面:1. USB 启动模式相对于传统的 BIOS 启动模式来说,具有更高的兼容性和灵活性,可以支持更多的硬件设备和操作系统。2. USB 启动...
点击进入详情页
本回答由浙江启扬智能科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询