ather): 重构数据源配置功能

- 移除 DataSourceConfig 中的 beanName 字段,使用 name 字段替代
- 新增 DataSourceConfigDTO 类作为数据源配置的传输对象
- 实现 DataSourceConfigConvert 接口,用于 DTO 和 DruidDataSource 之间的转换
- 更新 DataSourceConfigService 接口,使用 DTO 作为参数- 重构 DataSourceConfigServiceImpl 中的 add 方法,使用 DTO 和转换器
- 更新应用配置,移除全局的 driverClassName 配置- 新增 SQL Server 数据源支持
dev
1iyc 4 weeks ago
parent 4bd634fa63
commit e471b56281

@ -31,6 +31,8 @@
<poi.version>4.1.2</poi.version> <poi.version>4.1.2</poi.version>
<velocity.version>2.3</velocity.version> <velocity.version>2.3</velocity.version>
<jwt.version>0.9.1</jwt.version> <jwt.version>0.9.1</jwt.version>
<mapstruct.version>1.6.2</mapstruct.version>
<lombok.version>1.18.22</lombok.version>
</properties> </properties>
<!-- 依赖声明 --> <!-- 依赖声明 -->
@ -196,6 +198,13 @@
<version>${sync.version}</version> <version>${sync.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@ -222,6 +231,19 @@
<target>${java.version}</target> <target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding> <encoding>${project.build.sourceEncoding}</encoding>
<parameters>true</parameters> <parameters>true</parameters>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
</annotationProcessorPaths>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

@ -43,6 +43,11 @@
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<!-- 核心模块--> <!-- 核心模块-->
<dependency> <dependency>
<groupId>com.lyr</groupId> <groupId>com.lyr</groupId>
@ -67,6 +72,7 @@
<artifactId>sync-gather</artifactId> <artifactId>sync-gather</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>

@ -5,13 +5,12 @@ spring:
port: 6379 port: 6379
database: 1 database: 1
password: eGDiN3RRhRNzrzjd password: eGDiN3RRhRNzrzjd
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
druid: druid:
# 主库数据源 # 主库数据源
master: master:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${spring.redis.host}:3306/sync-data?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://${spring.redis.host}:3306/sync-data?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
password: K2bfP8rzG62ZSJGN password: K2bfP8rzG62ZSJGN
@ -19,6 +18,7 @@ spring:
slave: slave:
# 从数据源开关/默认关闭 # 从数据源开关/默认关闭
enabled: false enabled: false
driverClassName:
url: url:
username: username:
password: password:

@ -5,13 +5,12 @@ spring:
port: 6379 port: 6379
database: 1 database: 1
password: eGDiN3RRhRNzrzjd password: eGDiN3RRhRNzrzjd
datasource: datasource:
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
druid: druid:
# 主库数据源 # 主库数据源
master: master:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${spring.redis.host}:3306/sync-data?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://${spring.redis.host}:3306/sync-data?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root username: root
password: K2bfP8rzG62ZSJGN password: K2bfP8rzG62ZSJGN
@ -19,6 +18,7 @@ spring:
slave: slave:
# 从数据源开关/默认关闭 # 从数据源开关/默认关闭
enabled: false enabled: false
driverClassName:
url: url:
username: username:
password: password:

@ -114,6 +114,24 @@
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.2.1-jre</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -0,0 +1,31 @@
package com.lyr.common.core.domain;
import com.google.common.collect.ImmutableMap;
import com.lyr.common.constant.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.Map;
/**
*
*
* @author liyc
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ServiceResult extends HashMap<String, Object> {
private Integer code;
private String message;
private Map data;
public static ServiceResult success(String name) {
ImmutableMap<Object, Object> data1 = ImmutableMap.of();
return new ServiceResult(HttpStatus.SUCCESS, name, data1);
}
}

@ -36,6 +36,15 @@ public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationC
return (T) beanFactory.getBean(name); return (T) beanFactory.getBean(name);
} }
public static <T> T getBeanOfNull(String name) throws BeansException {
try {
return (T) beanFactory.getBean(name);
} catch (BeansException e) {
}
return null;
}
/** /**
* requiredType * requiredType
* *

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save