完善定时任务配置

This commit is contained in:
2024-01-07 09:25:35 +08:00
parent 2074e0cf6c
commit 69fb2bc48a
2 changed files with 13 additions and 4 deletions

View File

@@ -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);
}
}
};
}

View File

@@ -8,6 +8,7 @@
<property name="LOG_FILE" value="${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/${app}-${profile}.log"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>
<logger name="org.quartz" level="WARN"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>