新增:数据源预热;加密配置解密优化

This commit is contained in:
yangyang01000846
2026-01-23 17:00:35 +08:00
parent ee5a8367bc
commit 4e9b534485
3 changed files with 96 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
package com.sdm.common.config;//package com.sdm.project.config.mybatis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
import java.sql.Connection;
@Slf4j
@Configuration
public class DataSourcePreWarmer {
@Bean
public ApplicationRunner secondDataSourcePreWarmer(
@Qualifier("secondDataSource") DataSource secondDataSource) {
return args -> {
try (Connection conn = secondDataSource.getConnection()) {
log.info("✅ secondDataSource 预热成功,连接已建立: {}", conn);
} catch (Exception e) {
log.error("❌ secondDataSource 预热失败", e);
throw new RuntimeException(e);
}
};
}
@Bean
public ApplicationRunner mainDataSourcePreWarmer(
@Qualifier("masterDataSource") DataSource master,
@Qualifier("slaveDataSource") DataSource slave) {
return args -> {
try {
try (Connection c1 = master.getConnection()) {
log.info("✅ masterDataSource 预热成功: {}", c1);
}
try (Connection c2 = slave.getConnection()) {
log.info("✅ slaveDataSource 预热成功: {}", c2);
}
} catch (Exception e) {
log.error("❌ 主从数据源预热失败", e);
throw new RuntimeException(e);
}
};
}
}