@Component
public class UreportMasterDataSource implements BuildinDatasource {
private static final String NAME = "默认数据源";
@Autowired
private DataSource dataSource;
/**
* 数据源名称
**/
@Override
public String name() {
return NAME;
}
/**
* 获取连接 多个源的话再写个类实现BuildinDatasource 改下@ds里面指定的值
**/
@DS("master")
@Override
public Connection getConnection() {
try {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
return dataSource.getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}