add:PDA组盘、PDA入库、采购入库单
add:多数据源配置
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package org.nl.config;
|
||||
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Configuration
|
||||
@Import(DynamicDataSourceAutoConfiguration.class)
|
||||
public class DynamicDataSourceConfig {
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.nl.config.mybatis;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||
import com.baomidou.dynamic.datasource.ds.ItemDataSource;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
@@ -15,6 +18,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -53,7 +57,27 @@ public class MybatisPlusConfig {
|
||||
}
|
||||
@PostConstruct
|
||||
public void datainnit() {
|
||||
String url = ((DruidDataSource) dataSource).getUrl();
|
||||
// String url = ((DruidDataSource) dataSource).getUrl();
|
||||
String url = null;
|
||||
if (dataSource instanceof DynamicRoutingDataSource) {
|
||||
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
|
||||
Map<String, DataSource> dataSources = ds.getDataSources();
|
||||
for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
|
||||
if (entry != null){
|
||||
DataSource realDs = ((ItemDataSource) dataSources.get(entry.getKey())).getRealDataSource();
|
||||
if (realDs instanceof DruidDataSource) {
|
||||
url = ((DruidDataSource) realDs).getUrl();
|
||||
System.out.println("项目数据库地址:" + entry.getKey() + url);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (dataSources != null && dataSources.containsKey("master")) {
|
||||
// DataSource realDs = ((ItemDataSource) dataSources.get("master")).getRealDataSource();
|
||||
// if (realDs instanceof DruidDataSource) {
|
||||
// url = ((DruidDataSource) realDs).getUrl();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
System.out.println("项目数据库地址:" + url);
|
||||
log.debug("项目数据库地址:{}", url);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user