maven
3 天以前 5dbfaac33b7a1868e5753600aa5886ca13543cf3
src/main/java/com/ruoyi/inspectiontask/service/impl/QuartzConfig.java
@@ -1,5 +1,6 @@
package com.ruoyi.inspectiontask.service.impl;
import org.quartz.*;
import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
@@ -7,13 +8,21 @@
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;
import javax.sql.DataSource;
@Configuration
public class QuartzConfig {
    @Autowired
    private ApplicationContext applicationContext;
    // 假设已配置名为dataSource的数据源Bean
    @Autowired
    private DataSource dataSource;
    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
@@ -24,10 +33,17 @@
        jobFactory.setApplicationContext(applicationContext);
        schedulerFactory.setJobFactory(jobFactory);
        // 在schedulerFactoryBean()方法中添加
        schedulerFactory.setDataSource(dataSource);
        // 其他配置...
        return schedulerFactory;
    }
    @Bean
    public Scheduler scheduler() {
        return schedulerFactoryBean().getScheduler();
    }
    // 自定义JobFactory,支持自动注入
    public static class AutowiringSpringBeanJobFactory extends SpringBeanJobFactory
            implements ApplicationContextAware {