| | |
| | | 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; |
| | |
| | | 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() { |
| | |
| | | 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 { |