druid 项目中使用超过5个数据源会报错?

4zcjmb1e  于 2022-10-27  发布在  Druid
关注(0)|答案(1)|浏览(290)

@primary
@bean("dataSource")
public DataSource initDataSource(){
String defaultDataSourceId = dataSourceConfigProperties.getDefaultDataSourceId();

List<DataSourceModel> modelList = dataSourceConfigProperties.getDataSourceModel();
    Map<Object, Object> dataSourceMap = new HashMap<>();
    // build dataSource
    for(DataSourceModel model : modelList) {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(dataSourceConfigProperties.getDriverClassName());
        dataSource.setUrl(model.getUrl());
        dataSource.setUsername(model.getUsername());
        dataSource.setPassword(model.getPassword());
        dataSource.setInitialSize(dataSourceConfigProperties.getInitialSize());
        dataSource.setMinIdle(dataSourceConfigProperties.getMinIdle());
        dataSource.setMaxActive(dataSourceConfigProperties.getMaxActive());
        dataSource.setMaxWait(dataSourceConfigProperties.getMaxActive());
        dataSource.setTimeBetweenEvictionRunsMillis(dataSourceConfigProperties.getTimeBetweenEvictionRunsMillis());
        dataSource.setMinEvictableIdleTimeMillis(dataSourceConfigProperties.getMinEvictableIdleTimeMillis());
        dataSource.setTestWhileIdle(dataSourceConfigProperties.getTestWhileIdle());
        dataSource.setTestOnBorrow(dataSourceConfigProperties.getTestOnBorrow());
        dataSource.setValidationQuery(dataSourceConfigProperties.getValidationQuery());
        dataSource.setTestOnReturn(dataSourceConfigProperties.getTestOnReturn());
        dataSource.setPoolPreparedStatements(dataSourceConfigProperties.getPoolPreparedStatements());
        dataSource.setMaxPoolPreparedStatementPerConnectionSize(dataSourceConfigProperties.getMaxPoolPreparedStatementPerConnectionSize());
        dataSource.setConnectionProperties(dataSourceConfigProperties.getConnectionProperties());

        try {
            // 开启Druid的监控统计功能
            dataSource.setFilters(dataSourceConfigProperties.getFilters());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        // set another properties.......

        // put
        dataSourceMap.put(model.getId(), dataSource);
    }
    DynamicDataSource dataSource = new DynamicDataSource();
    dataSource.setDefaultTargetDataSource(dataSourceMap.get(defaultDataSourceId));
    dataSource.setTargetDataSources(dataSourceMap);
    return  dataSource;

数据源配置。
配置5个datasourcemodel就没问题,6个就有问题,切换到最后一个数据源就会报ORA-00942表或视图不存在。
把数据源顺序换换,还是最后一个会报错。有大佬解释一下吗?

dvtswwa3

dvtswwa31#

你创建多几个看看?创建10个,11个,看看,应该是你代码问题。我之前用到这个多数据源是没有问题的,另外你的报错信息也没有给出来,代码好像给得也不太完整。。。

相关问题