From 606c445cb8a4dee917ebb47477ab09892544b56e Mon Sep 17 00:00:00 2001 From: yangyang01000846 <15195822163@163.com> Date: Fri, 23 Jan 2026 18:43:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90=E9=A2=84=E7=83=AD=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/config/DataSourcePreWarmer.java | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/common/src/main/java/com/sdm/common/config/DataSourcePreWarmer.java b/common/src/main/java/com/sdm/common/config/DataSourcePreWarmer.java index a075b282..f45415c1 100644 --- a/common/src/main/java/com/sdm/common/config/DataSourcePreWarmer.java +++ b/common/src/main/java/com/sdm/common/config/DataSourcePreWarmer.java @@ -1,47 +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); - } - }; - } -} \ No newline at end of file +//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); +// } +// }; +// } +//} \ No newline at end of file