first Commit!!!
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package com.spring.infra.quartz;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.quartz.spi.JobFactory;
|
||||
import org.quartz.spi.TriggerFiredBundle;
|
||||
import org.springframework.batch.core.configuration.JobRegistry;
|
||||
import org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
import org.springframework.scheduling.quartz.SpringBeanJobFactory;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class QuartzConfig {
|
||||
|
||||
private final QuartzProperties quartzProperties;
|
||||
private final DataSource dataSource;
|
||||
private final PlatformTransactionManager transactionManager;
|
||||
|
||||
/**
|
||||
* JobRegistry 에 Job 을 자동으로 등록하기 위한 설정.
|
||||
*
|
||||
* @param jobRegistry ths Spring Batch Job Registry
|
||||
* @return JobRegistry BeanPostProcessor
|
||||
*/
|
||||
// @Bean
|
||||
// JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(JobRegistry jobRegistry) {
|
||||
// var jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor();
|
||||
// jobRegistryBeanPostProcessor.setJobRegistry(jobRegistry);
|
||||
// return jobRegistryBeanPostProcessor;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Quartz Schedule Job 에 의존성 주입
|
||||
*
|
||||
* @param beanFactory application context beanFactory
|
||||
* @return the job factory
|
||||
*/
|
||||
@Bean
|
||||
JobFactory jobFactory(AutowireCapableBeanFactory beanFactory) {
|
||||
return new SpringBeanJobFactory(){
|
||||
@Override
|
||||
protected @NonNull Object createJobInstance(@NonNull final TriggerFiredBundle bundle) throws Exception {
|
||||
var job = super.createJobInstance(bundle);
|
||||
beanFactory.autowireBean(job);
|
||||
return job;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Scheduler 전체를 관리하는 Manager.
|
||||
*
|
||||
* @param datasource Spring datasource
|
||||
* @param quartzProperties quartz config
|
||||
* @return the scheduler factory bean
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Bean
|
||||
SchedulerFactoryBean schedulerFactoryBean(JobFactory jobFactory) throws Exception {
|
||||
var factory = new SchedulerFactoryBean();
|
||||
factory.setSchedulerName("SampleProject-0.0.1");
|
||||
factory.setQuartzProperties(quartzProperties.toProperties());
|
||||
factory.setOverwriteExistingJobs(true); //Job Detail 데이터 Overwrite 유무
|
||||
factory.setDataSource(dataSource); //Schedule 관리를 Spring Datasource 에 위임
|
||||
factory.setTransactionManager(transactionManager);
|
||||
factory.setJobFactory(jobFactory);
|
||||
factory.setAutoStartup(true);
|
||||
factory.setWaitForJobsToCompleteOnShutdown(true);
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user