From 69fb2bc48a2cfa0f7f0daa93f6b84a60a8b77e95 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sun, 7 Jan 2024 09:25:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coal/spring/config/QuartzConfig.java | 16 ++++++++++++---- src/main/resources/logback-spring.xml | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/spring/config/QuartzConfig.java b/src/main/java/cn/lihongjie/coal/spring/config/QuartzConfig.java index 475de13e..c988836c 100644 --- a/src/main/java/cn/lihongjie/coal/spring/config/QuartzConfig.java +++ b/src/main/java/cn/lihongjie/coal/spring/config/QuartzConfig.java @@ -1,5 +1,9 @@ package cn.lihongjie.coal.spring.config; +import com.p6spy.engine.spy.P6DataSource; + +import lombok.SneakyThrows; + import org.flywaydb.core.Flyway; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer; @@ -14,20 +18,24 @@ import javax.sql.DataSource; @Configuration public class QuartzConfig { - @Autowired - Flyway flyway; + @Autowired Flyway flyway; @Autowired private DataSource dataSource; - + @Bean public SchedulerFactoryBeanCustomizer schedulerFactoryBeanCustomizer() { flyway.migrate(); return new SchedulerFactoryBeanCustomizer() { + @SneakyThrows @Override public void customize(SchedulerFactoryBean schedulerFactoryBean) { - schedulerFactoryBean.setDataSource(dataSource); + if (dataSource instanceof P6DataSource p6DataSource) { + schedulerFactoryBean.setDataSource(p6DataSource.unwrap(DataSource.class)); + } else { + schedulerFactoryBean.setDataSource(dataSource); + } } }; } diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 4702f1a6..214bc722 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -8,6 +8,7 @@ +