Ver Fonte

- 多数据库配置;

Gizmo há 2 anos atrás
pai
commit
ea9857ad06

+ 19 - 11
src/main/java/com/warewms/config/ActiveRecordConfig.java

@@ -1,12 +1,14 @@
 package com.warewms.config;
 
 import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
+import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
 import com.jfinal.template.source.ClassPathSourceFactory;
 import com.warewms.model._MappingKit;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
 import javax.sql.DataSource;
 
 @Component
@@ -16,8 +18,14 @@ public class ActiveRecordConfig {
     @Autowired
     private DataSource ds;
 
-//    @Resource(name = "secondDataSource")
-//    private DataSource dsSecond;
+    @Resource(name = "secondDataSource")
+    private DataSource dsSecond;
+
+    @Resource(name = "thirdDataSource")
+    private DataSource dsThird;
+
+    @Resource(name = "fourthDataSource")
+    private DataSource dsFourth;
 
     @Bean(initMethod="start", destroyMethod="stop",name = "activeRecordPlugin")
     public ActiveRecordPlugin init() {
@@ -29,13 +37,13 @@ public class ActiveRecordConfig {
         return arp;
     }
 
-//    @Bean(initMethod="start", destroyMethod="stop",name = "msSqlRecord")
-//    public ActiveRecordPlugin initMsSql() {
-//        ActiveRecordPlugin arp = new ActiveRecordPlugin("sqlServer",dsSecond);
-//        arp.getEngine().setSourceFactory(new ClassPathSourceFactory());
-//        arp.setShowSql(false);
-//        arp.setDialect(new SqlServerDialect());
-//        //arp.addMapping("T_SHKD_CUSTOMER", TShkdCustomer.class);
-//        return arp;
-//    }
+    @Bean(initMethod="start", destroyMethod="stop",name = "msSqlRecord")
+    public ActiveRecordPlugin initMsSql() {
+        ActiveRecordPlugin arp = new ActiveRecordPlugin(dsSecond);
+        arp.getEngine().setSourceFactory(new ClassPathSourceFactory());
+        arp.setShowSql(false);
+        arp.setDialect(new MysqlDialect());
+//        arp.addMapping("T_SHKD_CUSTOMER", TShkdCustomer.class);
+        return arp;
+    }
 }

+ 2 - 1
src/main/java/com/warewms/datasources/DataSourceNames.java

@@ -10,5 +10,6 @@ package com.warewms.datasources;
 public interface DataSourceNames {
     String FIRST = "first";
     String SECOND = "second";
-
+    String THIRD = "third";
+    String FOURTH = "fourth";
 }

+ 23 - 10
src/main/java/com/warewms/datasources/DynamicDataSourceConfig.java

@@ -30,8 +30,25 @@ public class DynamicDataSourceConfig {
     @Bean
     @ConfigurationProperties("spring.datasource.druid.first")
     public DruidDataSource firstDataSource(){
-        DruidDataSource druidDataSource = DruidDataSourceBuilder.create().build();
-        return druidDataSource;
+        return DruidDataSourceBuilder.create().build();
+    }
+
+    @Bean
+    @ConfigurationProperties("spring.datasource.druid.second")
+    public DruidDataSource secondDataSource(){
+        return DruidDataSourceBuilder.create().build();
+    }
+
+    @Bean
+    @ConfigurationProperties("spring.datasource.druid.third")
+    public DruidDataSource thirdDataSource(){
+        return DruidDataSourceBuilder.create().build();
+    }
+
+    @Bean
+    @ConfigurationProperties("spring.datasource.druid.fourth")
+    public DruidDataSource fourthDataSource(){
+        return DruidDataSourceBuilder.create().build();
     }
 
     public DruidDataSource profileDataSource(){
@@ -52,18 +69,14 @@ public class DynamicDataSourceConfig {
         return filter;
     }
 
-//    @Bean
-//    @ConfigurationProperties("spring.datasource.druid.second")
-//    public DruidDataSource secondDataSource(){
-//        return DruidDataSourceBuilder.create().build();
-//    }
-
     @Bean
     @Primary
-    public DynamicDataSource dataSource(DataSource firstDataSource, DataSource secondDataSource) {
+    public DynamicDataSource dataSource(DataSource firstDataSource, DataSource secondDataSource, DataSource thirdDataSource, DataSource fourthDataSource) {
         Map<Object, Object> targetDataSources = new HashMap<>();
         targetDataSources.put(DataSourceNames.FIRST, firstDataSource);
-        //targetDataSources.put(DataSourceNames.SECOND, secondDataSource);
+        targetDataSources.put(DataSourceNames.SECOND, secondDataSource);
+        targetDataSources.put(DataSourceNames.THIRD, thirdDataSource);
+        targetDataSources.put(DataSourceNames.FOURTH, fourthDataSource);
         return new DynamicDataSource(firstDataSource, targetDataSources);
     }
 }