1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package com.yihu.jw.care.config.quartz;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.beans.factory.config.PropertiesFactoryBean;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.core.io.ClassPathResource;
- import org.springframework.scheduling.quartz.SchedulerFactoryBean;
- import javax.sql.DataSource;
- import java.io.IOException;
- import java.util.Properties;
- /**
- * Created by chenweida on 2016/2/3.
- */
- @Configuration
- public class SchedulerConfig {
- @Autowired
- private ApplicationContext applicationContext;
- @Autowired
- private org.quartz.spi.JobFactory jobFactory;
- @Autowired
- private DataSource dataSource;
- @Value("${quartz.name}")
- private String schedulerFactoryBeanName;
- @Bean
- SchedulerFactoryBean schedulerFactoryBeanWlyy() throws IOException {
- SchedulerFactoryBean bean = new SchedulerFactoryBean();
- bean.setJobFactory(jobFactory);
- bean.setApplicationContext(this.applicationContext);
- bean.setOverwriteExistingJobs(true);
- bean.setStartupDelay(20);// 延时启动
- bean.setBeanName(schedulerFactoryBeanName);
- bean.setAutoStartup(true);
- bean.setDataSource(dataSource);
- bean.setQuartzProperties(quartzProperties());
- return bean;
- }
- /**
- * quartz配置文件
- * @return
- * @throws IOException
- */
- @Bean
- public Properties quartzProperties() throws IOException {
- PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
- propertiesFactoryBean.setLocation(new ClassPathResource("/quartz.properties"));
- propertiesFactoryBean.afterPropertiesSet();
- return propertiesFactoryBean.getObject();
- }
- }
|