From 66350ce12dba3c2343ed05037c9e3a13750eece5 Mon Sep 17 00:00:00 2001
From: songhuangfeng123 <shf18767906695@163.com>
Date: 星期一, 25 七月 2022 15:17:37 +0800
Subject: [PATCH] 配置文件修改
---
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java | 16 +++++++
safePlatfrom-out-web/pom.xml | 10 +++++
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/MyBatisConfigGoalManage.java | 2
safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/MyBatisConfigEquipment.java | 75 +++++++++++++++++++++++++++++++++++++
4 files changed, 101 insertions(+), 2 deletions(-)
diff --git a/safePlatfrom-out-web/pom.xml b/safePlatfrom-out-web/pom.xml
index e172abe..d609001 100644
--- a/safePlatfrom-out-web/pom.xml
+++ b/safePlatfrom-out-web/pom.xml
@@ -40,6 +40,16 @@
</dependency>
<dependency>
<groupId>com.gkhy.safePlatfrom</groupId>
+ <artifactId>equipment</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.gkhy.safePlatfrom</groupId>
+ <artifactId>equipment-rpc-provider</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.gkhy.safePlatfrom</groupId>
<artifactId>incident-manage-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java
index d7922fd..520ae20 100644
--- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/DruidConfig.java
@@ -79,6 +79,20 @@
return ds;
}
+ @Autowired
+ @Primary
+ @Bean(name = "dsEquipment")
+ public AtomikosDataSourceBean dsEquipment(Environment env) {
+ AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
+ Properties prop = build(env, "spring.datasource.equipment.");
+ ds.setXaDataSourceClassName(datasourceClass);
+// ds.setXaDataSourceClassName("com.alibaba.druid.pool.xa.DruidXADataSource");
+ ds.setUniqueResourceName("equipment");
+ ds.setPoolSize(2);
+ ds.setXaProperties(prop);
+ return ds;
+ }
+
/**
* 注入事物管理器
@@ -162,4 +176,4 @@
return wallFilter;
}
-}
\ No newline at end of file
+}
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/MyBatisConfigEquipment.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/MyBatisConfigEquipment.java
new file mode 100644
index 0000000..ad051a5
--- /dev/null
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/MyBatisConfigEquipment.java
@@ -0,0 +1,75 @@
+package com.gkhy.safePlatform.config.database;
+
+import com.alibaba.druid.pool.DruidDataSource;
+import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
+import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
+import org.apache.ibatis.plugin.Interceptor;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.stereotype.Repository;
+
+import javax.sql.DataSource;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+@Configuration
+@MapperScan(basePackages = {"com.gkhy.safePlatform.equipment"},
+ sqlSessionTemplateRef = "sqlTemplateEquipment",annotationClass =
+ Repository.class)
+public class MyBatisConfigEquipment {
+
+ @Autowired
+ @Qualifier("dsEquipment")
+ DataSource dsEquipment;
+
+ @Autowired
+ private MybatisPlusInterceptor mybatisPlusInterceptor;
+
+ @Bean(name = "datasourceEquipment")
+ @ConfigurationProperties(prefix = "spring.datasource.equipment")
+ public DruidDataSource druidDataSourceA(){
+ return DruidDataSourceBuilder.create().build();
+ }
+
+ @Bean(name = "sqlFactoryEquipment")
+ public SqlSessionFactory sqlSessionFactory(@Qualifier("datasourceEquipment") DruidDataSource dataSource)
+ throws Exception
+ {
+ MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean();
+ factoryBean.setDataSource(dataSource);
+ ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
+
+ //-------------------
+ Resource[] rs1 = resolver.getResources("classpath*:config/mapper/equipment/**/**Mapper.xml");
+// Resource[] rs2 = resolver.getResources("classpath*:config/mapper/goalManage/**Mapper.xml");
+ ArrayList<Resource> resourceArrayList = new ArrayList<>(Arrays.asList(rs1));
+// resourceArrayList.addAll(new ArrayList<>(Arrays.asList(rs2)));
+ Resource[] resourceArray = new Resource[resourceArrayList.size()];
+ resourceArrayList.toArray(resourceArray);
+ factoryBean.setMapperLocations(resourceArray);
+ //-------------------
+
+// factoryBean.setMapperLocations(resolver.getResources("classpath*:config/mapper/**/**Mapper.xml"));
+ //设置分页插件
+ Interceptor[] plugins = {mybatisPlusInterceptor};
+ factoryBean.setPlugins(plugins);
+ return factoryBean.getObject();
+ }
+
+ @Bean(name = "sqlTemplateEquipment")
+ public SqlSessionTemplate sqlSessionTemplate(@Qualifier("sqlFactoryEquipment") SqlSessionFactory sqlSessionFactory)
+ {
+ return new SqlSessionTemplate(sqlSessionFactory);
+ }
+
+}
diff --git a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/MyBatisConfigGoalManage.java b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/MyBatisConfigGoalManage.java
index 38148be..484e9ca 100644
--- a/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/MyBatisConfigGoalManage.java
+++ b/safePlatfrom-out-web/src/main/java/com/gkhy/safePlatform/config/database/MyBatisConfigGoalManage.java
@@ -23,7 +23,7 @@
import java.util.Arrays;
@Configuration
-@MapperScan(basePackages = {"com.gkhy.safePlatform.goalManage"},
+@MapperScan(basePackages = {"com.gkhy.safePlatform.targetDuty"},
sqlSessionTemplateRef = "sqlTemplateGoalManage",annotationClass =
Repository.class)
public class MyBatisConfigGoalManage {
--
Gitblit v1.9.2