Search in sources :

Example 16 with DynamicRoutingDataSource

use of com.baomidou.dynamic.datasource.DynamicRoutingDataSource in project longmarch by yuyueqty.

the class DataSourceController method add.

@ApiOperation(value = "添加数据源")
@PostMapping("/add")
public Set<String> add(@Validated @RequestBody DataSourceDTO dto) {
    DataSourceProperty dataSourceProperty = new DataSourceProperty();
    BeanUtils.copyProperties(dto, dataSourceProperty);
    DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
    DataSource dataSource = dataSourceCreator.createDataSource(dataSourceProperty);
    ds.addDataSource(dto.getPoolName(), dataSource);
    return ds.getDataSources().keySet();
}
Also used : DataSourceProperty(com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty) DynamicRoutingDataSource(com.baomidou.dynamic.datasource.DynamicRoutingDataSource) DataSource(javax.sql.DataSource) DynamicRoutingDataSource(com.baomidou.dynamic.datasource.DynamicRoutingDataSource) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

DynamicRoutingDataSource (com.baomidou.dynamic.datasource.DynamicRoutingDataSource)16 Bean (org.springframework.context.annotation.Bean)8 Primary (org.springframework.context.annotation.Primary)6 DataSource (javax.sql.DataSource)5 DataSourceProperty (com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty)4 ApiOperation (io.swagger.annotations.ApiOperation)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 DbInfo (com.maxqiu.demo.system.entity.DbInfo)1 ServiceException (com.ruoyi.common.exception.ServiceException)1 GenDsInfo (com.xhuicloud.common.datasource.entity.GenDsInfo)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1