主从库双数据源
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
package top.wms.admin.common.config.mybatis;
|
||||||
|
|
||||||
|
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||||
|
import top.wms.admin.common.constant.DataSourceContextHolder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态数据源路由
|
||||||
|
*
|
||||||
|
* @author Admin
|
||||||
|
* @since 2024/12/22
|
||||||
|
*/
|
||||||
|
public class DynamicRoutingDataSource extends AbstractRoutingDataSource {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object determineCurrentLookupKey() {
|
||||||
|
return DataSourceContextHolder.getDataSource();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package top.wms.admin.common.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源上下文 Holder
|
||||||
|
*
|
||||||
|
* @author Admin
|
||||||
|
* @since 2024/12/22
|
||||||
|
*/
|
||||||
|
public class DataSourceContextHolder {
|
||||||
|
|
||||||
|
private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
|
||||||
|
|
||||||
|
private DataSourceContextHolder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置数据源
|
||||||
|
*
|
||||||
|
* @param dataSource 数据源标识
|
||||||
|
*/
|
||||||
|
public static void setDataSource(String dataSource) {
|
||||||
|
CONTEXT_HOLDER.set(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据源
|
||||||
|
*
|
||||||
|
* @return 数据源标识
|
||||||
|
*/
|
||||||
|
public static String getDataSource() {
|
||||||
|
return CONTEXT_HOLDER.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除数据源
|
||||||
|
*/
|
||||||
|
public static void clearDataSource() {
|
||||||
|
CONTEXT_HOLDER.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -74,6 +74,11 @@ public class UserContext implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String clientId;
|
private String clientId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源标识
|
||||||
|
*/
|
||||||
|
private String dataSource;
|
||||||
|
|
||||||
public UserContext(Set<String> permissions, Set<RoleContext> roles, Integer passwordExpirationDays) {
|
public UserContext(Set<String> permissions, Set<RoleContext> roles, Integer passwordExpirationDays) {
|
||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
this.setRoles(roles);
|
this.setRoles(roles);
|
||||||
@@ -113,4 +118,4 @@ public class UserContext implements Serializable {
|
|||||||
}
|
}
|
||||||
return this.pwdResetTime.plusDays(this.passwordExpirationDays).isBefore(LocalDateTime.now());
|
return this.pwdResetTime.plusDays(this.passwordExpirationDays).isBefore(LocalDateTime.now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package top.wms.admin.common.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源枚举
|
||||||
|
*
|
||||||
|
* @author Admin
|
||||||
|
* @since 2024/12/22
|
||||||
|
*/
|
||||||
|
public enum DataSourceEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主数据源
|
||||||
|
*/
|
||||||
|
WMS("wms"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从数据源
|
||||||
|
*/
|
||||||
|
WMS2("wms2");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
DataSourceEnum(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import top.wms.admin.auth.model.req.LoginReq;
|
import top.wms.admin.auth.model.req.LoginReq;
|
||||||
|
import top.wms.admin.common.constant.DataSourceContextHolder;
|
||||||
import top.wms.admin.common.context.RoleContext;
|
import top.wms.admin.common.context.RoleContext;
|
||||||
import top.wms.admin.common.context.UserContext;
|
import top.wms.admin.common.context.UserContext;
|
||||||
import top.wms.admin.common.context.UserContextHolder;
|
import top.wms.admin.common.context.UserContextHolder;
|
||||||
@@ -91,6 +92,14 @@ public abstract class AbstractLoginHandler<T extends LoginReq> implements LoginH
|
|||||||
userContext.setClientType(client.getClientType());
|
userContext.setClientType(client.getClientType());
|
||||||
model.setExtra(CLIENT_ID, client.getClientId());
|
model.setExtra(CLIENT_ID, client.getClientId());
|
||||||
userContext.setClientId(client.getClientId());
|
userContext.setClientId(client.getClientId());
|
||||||
|
// 设置数据源(如果用户未配置,则使用默认主库)
|
||||||
|
String dataSource = user.getDataSource();
|
||||||
|
if (dataSource == null || dataSource.isEmpty()) {
|
||||||
|
dataSource = "wms"; // 默认主库
|
||||||
|
}
|
||||||
|
userContext.setDataSource(dataSource);
|
||||||
|
DataSourceContextHolder.setDataSource(dataSource);
|
||||||
|
|
||||||
// 登录并缓存用户信息
|
// 登录并缓存用户信息
|
||||||
StpUtil.login(userContext.getId(), model.setExtraData(BeanUtil.beanToMap(new UserExtraContext(SpringWebUtils
|
StpUtil.login(userContext.getId(), model.setExtraData(BeanUtil.beanToMap(new UserExtraContext(SpringWebUtils
|
||||||
.getRequest()))));
|
.getRequest()))));
|
||||||
@@ -108,4 +117,4 @@ public abstract class AbstractLoginHandler<T extends LoginReq> implements LoginH
|
|||||||
// DeptDO dept = deptService.getById(user.getDeptId());
|
// DeptDO dept = deptService.getById(user.getDeptId());
|
||||||
// CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, dept.getStatus(), "此账号所属部门已被禁用,如有疑问,请联系管理员");
|
// CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, dept.getStatus(), "此账号所属部门已被禁用,如有疑问,请联系管理员");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,8 @@ import top.continew.starter.data.mp.base.BaseMapper;
|
|||||||
import top.wms.admin.fullWorkOrder.model.entity.FullWorkOrderDO;
|
import top.wms.admin.fullWorkOrder.model.entity.FullWorkOrderDO;
|
||||||
import top.wms.admin.fullWorkOrder.model.resp.FullWorkOrderResp;
|
import top.wms.admin.fullWorkOrder.model.resp.FullWorkOrderResp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 整箱领取记录 Mapper
|
* 整箱领取记录 Mapper
|
||||||
*
|
*
|
||||||
@@ -21,4 +23,6 @@ public interface FullWorkOrderMapper extends BaseMapper<FullWorkOrderDO> {
|
|||||||
|
|
||||||
IPage<FullWorkOrderResp> selectFullWorkOrderPage(@Param("page") Page<Object> objectPage,
|
IPage<FullWorkOrderResp> selectFullWorkOrderPage(@Param("page") Page<Object> objectPage,
|
||||||
@Param(Constants.WRAPPER) QueryWrapper<FullWorkOrderDO> queryWrapper);
|
@Param(Constants.WRAPPER) QueryWrapper<FullWorkOrderDO> queryWrapper);
|
||||||
|
|
||||||
|
List<FullWorkOrderResp> selectFullWorkOrderExport(@Param(Constants.WRAPPER) QueryWrapper<FullWorkOrderDO> queryWrapper);
|
||||||
}
|
}
|
||||||
@@ -92,4 +92,9 @@ public class UserDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private Long equipmentId;
|
private Long equipmentId;
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* 数据源标识(wms/wms2)
|
||||||
|
*/
|
||||||
|
private String dataSource;
|
||||||
|
}
|
||||||
@@ -93,6 +93,12 @@ public class UserReq implements Serializable {
|
|||||||
@Schema(description = "状态", example = "1")
|
@Schema(description = "状态", example = "1")
|
||||||
private DisEnableStatusEnum status;
|
private DisEnableStatusEnum status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@Schema(description = "数据源")
|
||||||
|
private String dataSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备ID
|
* 设备ID
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -116,6 +116,12 @@ public class UserDetailResp extends BaseDetailResp {
|
|||||||
@Schema(description = "设备ID")
|
@Schema(description = "设备ID")
|
||||||
private Long equipmentId;
|
private Long equipmentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源
|
||||||
|
*/
|
||||||
|
@Schema(description = "数据源")
|
||||||
|
private String dataSource;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean getDisabled() {
|
public Boolean getDisabled() {
|
||||||
return this.getIsSystem() || Objects.equals(this.getId(), UserContextHolder.getUserId());
|
return this.getIsSystem() || Objects.equals(this.getId(), UserContextHolder.getUserId());
|
||||||
|
|||||||
@@ -81,6 +81,12 @@ public class UserResp extends BaseDetailResp {
|
|||||||
@Schema(description = "描述", example = "张三描述信息")
|
@Schema(description = "描述", example = "张三描述信息")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
@Schema(description = "数据源")
|
||||||
|
private String dataSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色名称列表
|
* 角色名称列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,4 +12,15 @@
|
|||||||
left join sys_user u on f.create_user = u.id
|
left join sys_user u on f.create_user = u.id
|
||||||
${ew.customSqlSegment}
|
${ew.customSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectFullWorkOrderExport" resultType="top.wms.admin.fullWorkOrder.model.resp.FullWorkOrderResp">
|
||||||
|
select
|
||||||
|
f.*,
|
||||||
|
m.material_name materialName,
|
||||||
|
u.username createUserString
|
||||||
|
from
|
||||||
|
sys_full_work_order f
|
||||||
|
left join sys_material_info m on f.material_code = m.encoding
|
||||||
|
left join sys_user u on f.create_user = u.id
|
||||||
|
${ew.customSqlSegment}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -22,7 +22,8 @@
|
|||||||
t1.is_system,
|
t1.is_system,
|
||||||
t1.pwd_reset_time,
|
t1.pwd_reset_time,
|
||||||
t1.dept_id,
|
t1.dept_id,
|
||||||
t2.name AS deptName
|
t2.name AS deptName,
|
||||||
|
t1.data_source
|
||||||
FROM sys_user AS t1
|
FROM sys_user AS t1
|
||||||
LEFT JOIN sys_dept AS t2 ON t2.id = t1.dept_id
|
LEFT JOIN sys_dept AS t2 ON t2.id = t1.dept_id
|
||||||
</sql>
|
</sql>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.dromara.x.file.storage.spring.EnableFileStorage;
|
import org.dromara.x.file.storage.spring.EnableFileStorage;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -28,7 +29,7 @@ import top.continew.starter.web.model.R;
|
|||||||
@EnableGlobalResponse
|
@EnableGlobalResponse
|
||||||
@EnableCrudRestController
|
@EnableCrudRestController
|
||||||
@RestController
|
@RestController
|
||||||
@SpringBootApplication
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
public class WmsAdminApplication {
|
public class WmsAdminApplication {
|
||||||
@@ -46,4 +47,4 @@ public class WmsAdminApplication {
|
|||||||
return R.ok(projectProperties);
|
return R.ok(projectProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package top.wms.admin.config;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import top.wms.admin.common.config.mybatis.DynamicRoutingDataSource;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态数据源配置
|
||||||
|
*
|
||||||
|
* @author Admin
|
||||||
|
* @since 2024/12/22
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class DynamicDataSourceConfig {
|
||||||
|
|
||||||
|
@Value("${spring.datasource.wms.url}")
|
||||||
|
private String wmsUrl;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.wms.username}")
|
||||||
|
private String wmsUsername;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.wms.password}")
|
||||||
|
private String wmsPassword;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.wms2.url}")
|
||||||
|
private String wms2Url;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.wms2.username}")
|
||||||
|
private String wms2Username;
|
||||||
|
|
||||||
|
@Value("${spring.datasource.wms2.password}")
|
||||||
|
private String wms2Password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主数据源(wms)
|
||||||
|
*/
|
||||||
|
@Bean("wmsDataSource")
|
||||||
|
public DataSource wmsDataSource() {
|
||||||
|
HikariConfig config = new HikariConfig();
|
||||||
|
config.setDriverClassName("com.p6spy.engine.spy.P6SpyDriver");
|
||||||
|
config.setJdbcUrl(wmsUrl);
|
||||||
|
config.setUsername(wmsUsername);
|
||||||
|
config.setPassword(wmsPassword);
|
||||||
|
config.setMaximumPoolSize(20);
|
||||||
|
config.setConnectionTimeout(30000);
|
||||||
|
config.setIdleTimeout(600000);
|
||||||
|
config.setKeepaliveTime(30000);
|
||||||
|
config.setMaxLifetime(1800000);
|
||||||
|
return new HikariDataSource(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从数据源(wms2)
|
||||||
|
*/
|
||||||
|
@Bean("wms2DataSource")
|
||||||
|
public DataSource wms2DataSource() {
|
||||||
|
HikariConfig config = new HikariConfig();
|
||||||
|
config.setDriverClassName("com.p6spy.engine.spy.P6SpyDriver");
|
||||||
|
config.setJdbcUrl(wms2Url);
|
||||||
|
config.setUsername(wms2Username);
|
||||||
|
config.setPassword(wms2Password);
|
||||||
|
config.setMaximumPoolSize(20);
|
||||||
|
config.setConnectionTimeout(30000);
|
||||||
|
config.setIdleTimeout(600000);
|
||||||
|
config.setKeepaliveTime(30000);
|
||||||
|
config.setMaxLifetime(1800000);
|
||||||
|
return new HikariDataSource(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态数据源
|
||||||
|
*/
|
||||||
|
@Bean("dynamicDataSource")
|
||||||
|
@Primary
|
||||||
|
public DataSource dynamicDataSource(DataSource wmsDataSource, DataSource wms2DataSource) {
|
||||||
|
DynamicRoutingDataSource dynamicRoutingDataSource = new DynamicRoutingDataSource();
|
||||||
|
|
||||||
|
// 设置默认数据源
|
||||||
|
dynamicRoutingDataSource.setDefaultTargetDataSource(wmsDataSource);
|
||||||
|
|
||||||
|
// 设置数据源映射
|
||||||
|
Map<Object, Object> dataSourceMap = new HashMap<>();
|
||||||
|
dataSourceMap.put("wms", wmsDataSource);
|
||||||
|
dataSourceMap.put("wms2", wms2DataSource);
|
||||||
|
dynamicRoutingDataSource.setTargetDataSources(dataSourceMap);
|
||||||
|
|
||||||
|
// 必须调用此方法,否则首次获取数据源时会失败
|
||||||
|
dynamicRoutingDataSource.afterPropertiesSet();
|
||||||
|
|
||||||
|
return dynamicRoutingDataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事务管理器
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public PlatformTransactionManager transactionManager(DataSource dynamicDataSource) {
|
||||||
|
return new DataSourceTransactionManager(dynamicDataSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package top.wms.admin.config;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
import top.wms.admin.common.constant.DataSourceContextHolder;
|
||||||
|
import top.wms.admin.common.context.UserContext;
|
||||||
|
import top.wms.admin.common.context.UserContextHolder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态数据源拦截器
|
||||||
|
* 在每次请求时根据当前登录用户切换数据源
|
||||||
|
*
|
||||||
|
* @author Admin
|
||||||
|
* @since 2024/12/22
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class DynamicDataSourceInterceptor implements HandlerInterceptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
Object handler) throws Exception {
|
||||||
|
String requestUri = request.getRequestURI();
|
||||||
|
|
||||||
|
// 认证相关接口始终使用主库(wms),确保用户验证和权限获取在主库进行
|
||||||
|
if (requestUri.contains("/auth/login") || requestUri.contains("/auth/user/info") || requestUri
|
||||||
|
.contains("/auth/user/route") || requestUri.contains("/auth/logout")) {
|
||||||
|
DataSourceContextHolder.setDataSource("wms");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果用户已登录,从用户上下文获取数据源并设置
|
||||||
|
if (StpUtil.isLogin()) {
|
||||||
|
try {
|
||||||
|
UserContext userContext = UserContextHolder.getContext();
|
||||||
|
if (userContext != null && userContext.getDataSource() != null) {
|
||||||
|
DataSourceContextHolder.setDataSource(userContext.getDataSource());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 如果获取用户上下文失败,使用默认数据源
|
||||||
|
DataSourceContextHolder.clearDataSource();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterCompletion(HttpServletRequest request,
|
||||||
|
HttpServletResponse response,
|
||||||
|
Object handler,
|
||||||
|
@Nullable Exception ex) throws Exception {
|
||||||
|
// 请求结束后清除数据源上下文
|
||||||
|
DataSourceContextHolder.clearDataSource();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package top.wms.admin.config;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebMvc 配置
|
||||||
|
*
|
||||||
|
* @author Admin
|
||||||
|
* @since 2024/12/22
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WebMvcConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
private final DynamicDataSourceInterceptor dynamicDataSourceInterceptor;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
// 注册动态数据源拦截器,优先级高于其他拦截器
|
||||||
|
registry.addInterceptor(dynamicDataSourceInterceptor)
|
||||||
|
.addPathPatterns("/**")
|
||||||
|
.excludePathPatterns("/error", "/doc.html", "/webjars/**", "/swagger-ui/**", "/swagger-resources/**", "/*/api-docs/**", "/favicon.ico");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,33 +16,36 @@ spring:
|
|||||||
|
|
||||||
--- ### 数据源配置
|
--- ### 数据源配置
|
||||||
spring.datasource:
|
spring.datasource:
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
# 主数据源(wms)
|
||||||
# 请务必提前创建好名为 wms_admin 的数据库,如果使用其他数据库名请注意同步修改 DB_NAME 配置
|
wms:
|
||||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/wms?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
username: root
|
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||||
# password: root
|
url: jdbc:p6spy:mysql://127.0.0.1:3306/wms?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||||
password: test123$
|
username: root
|
||||||
# PostgreSQL 配置
|
# password: root
|
||||||
# url: jdbc:p6spy:mysql://192.168.2.30:${DB_PORT:3306}/continew?serverTimezone=Asia/Shanghai&useSSL=true&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
password: test123$
|
||||||
# username: ${DB_USER:root}
|
# Hikari 连接池配置
|
||||||
# password: ${DB_PWD:SQLsql123}
|
hikari:
|
||||||
# url: jdbc:p6spy:mysql://81.68.71.142:${DB_PORT:3306}/continew?serverTimezone=Asia/Shanghai&useSSL=true&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
maximum-pool-size: 20
|
||||||
# username: ${DB_USER:root}
|
connection-timeout: 30000
|
||||||
# password: ${DB_PWD:MYsql12@}
|
idle-timeout: 600000
|
||||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
keepaliveTime: 30000
|
||||||
# Hikari 连接池配置
|
max-lifetime: 1800000
|
||||||
hikari:
|
# 从数据源(wms2)
|
||||||
# 最大连接数量(默认 10,根据实际环境调整)
|
wms2:
|
||||||
# 注意:当连接达到上限,并且没有空闲连接可用时,获取连接将在超时前阻塞最多 connectionTimeout 毫秒
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
maximum-pool-size: 20
|
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||||
# 获取连接超时时间(默认 30000 毫秒,30 秒)
|
url: jdbc:p6spy:mysql://127.0.0.1:3306/wms2?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||||
connection-timeout: 30000
|
username: root
|
||||||
# 空闲连接最大存活时间(默认 600000 毫秒,10 分钟)
|
# password: root
|
||||||
idle-timeout: 600000
|
password: test123$
|
||||||
# 保持连接活动的频率,以防止它被数据库或网络基础设施超时。该值必须小于 maxLifetime(默认 0,禁用)
|
# Hikari 连接池配置
|
||||||
keepaliveTime: 30000
|
hikari:
|
||||||
# 连接最大生存时间(默认 1800000 毫秒,30 分钟)
|
maximum-pool-size: 20
|
||||||
max-lifetime: 1800000
|
connection-timeout: 30000
|
||||||
|
idle-timeout: 600000
|
||||||
|
keepaliveTime: 30000
|
||||||
|
max-lifetime: 1800000
|
||||||
## Liquibase 配置
|
## Liquibase 配置
|
||||||
spring.liquibase:
|
spring.liquibase:
|
||||||
# 是否启用
|
# 是否启用
|
||||||
|
|||||||
Reference in New Issue
Block a user