Spring boot 使用作业库';org.quartz.siml.RAMJobStore';-它不支持持久性。并且不是群集的

Spring boot 使用作业库';org.quartz.siml.RAMJobStore';-它不支持持久性。并且不是群集的,spring-boot,spring-batch,quartz-scheduler,Spring Boot,Spring Batch,Quartz Scheduler,我知道这已经被问了很多次了,但我不能 找到问题的答案。我试着每20秒安排一次我的春季批次,但是失败了 QuartzConfiguration.java @Configuration public class QuartzConfiguration { @Autowired private JobLauncher jobLauncher; @Autowired private JobLocator jobLocator; @Bean public

我知道这已经被问了很多次了,但我不能 找到问题的答案。我试着每20秒安排一次我的春季批次,但是失败了

QuartzConfiguration.java

@Configuration
public class QuartzConfiguration {

    @Autowired
    private JobLauncher jobLauncher;
    @Autowired
    private JobLocator jobLocator;

    @Bean
    public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(JobRegistry jobRegistry) {
        JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor();
        jobRegistryBeanPostProcessor.setJobRegistry(jobRegistry);
        return jobRegistryBeanPostProcessor;
    }

    @Bean
    public JobDetailFactoryBean jobDetailFactoryBean() {
        JobDetailFactoryBean jobfactory = new JobDetailFactoryBean();
        jobfactory.setJobClass(QuartzJobLauncher.class);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("jobName", "Test_Job");
        map.put("jobLauncher", jobLauncher);
        map.put("jobLocator", jobLocator);
        jobfactory.setJobDataAsMap(map);
        jobfactory.setGroup("group");
        jobfactory.setName("job");
        return jobfactory;
    }

    // Job is scheduled after every 20 sec
    @Bean
    public CronTriggerFactoryBean cronTriggerFactoryBean() {
        CronTriggerFactoryBean ctFactory = new CronTriggerFactoryBean();
        ctFactory.setJobDetail(jobDetailFactoryBean().getObject());
        ctFactory.setStartDelay(3000);
        ctFactory.setName("cron_trigger");
        ctFactory.setGroup("cron_group");
        ctFactory.setCronExpression("0/20 * * * * ?");
        return ctFactory;
    }

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
        scheduler.setTriggers(cronTriggerFactoryBean().getObject());
        return scheduler;
    }

}
@SpringBootApplication
@EnableBatchProcessing
@Import(QuartzConfiguration.class)
public class BatchApplication {

    public static void main(String[] args) {
        SpringApplication.run(BatchApplication.class, args);
    }
}
BatchConfig.java

@Configuration
public class BatchConfig {

    @Autowired
    JobBuilderFactory jobBuilderFactory;

    @Autowired
    StepBuilderFactory stepBuilderFactory;

    @Bean
    public Tasklet task1()
    {
        return new Tasklet(){

            @Override
            public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
                // TODO Auto-generated method stub
                System.out.println("hello world");
                return RepeatStatus.FINISHED;
            }
        };
    }
    @Bean
    public Step step1(){

        return stepBuilderFactory.get("step1")
                .tasklet(task1())
                .build();
    }

    @Bean
    public Job job1()
    {
        return jobBuilderFactory.get("job1")
                .start(step1())
                .build();
    }


}
BatchApplication.java

@Configuration
public class QuartzConfiguration {

    @Autowired
    private JobLauncher jobLauncher;
    @Autowired
    private JobLocator jobLocator;

    @Bean
    public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor(JobRegistry jobRegistry) {
        JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor();
        jobRegistryBeanPostProcessor.setJobRegistry(jobRegistry);
        return jobRegistryBeanPostProcessor;
    }

    @Bean
    public JobDetailFactoryBean jobDetailFactoryBean() {
        JobDetailFactoryBean jobfactory = new JobDetailFactoryBean();
        jobfactory.setJobClass(QuartzJobLauncher.class);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("jobName", "Test_Job");
        map.put("jobLauncher", jobLauncher);
        map.put("jobLocator", jobLocator);
        jobfactory.setJobDataAsMap(map);
        jobfactory.setGroup("group");
        jobfactory.setName("job");
        return jobfactory;
    }

    // Job is scheduled after every 20 sec
    @Bean
    public CronTriggerFactoryBean cronTriggerFactoryBean() {
        CronTriggerFactoryBean ctFactory = new CronTriggerFactoryBean();
        ctFactory.setJobDetail(jobDetailFactoryBean().getObject());
        ctFactory.setStartDelay(3000);
        ctFactory.setName("cron_trigger");
        ctFactory.setGroup("cron_group");
        ctFactory.setCronExpression("0/20 * * * * ?");
        return ctFactory;
    }

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean() {
        SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
        scheduler.setTriggers(cronTriggerFactoryBean().getObject());
        return scheduler;
    }

}
@SpringBootApplication
@EnableBatchProcessing
@Import(QuartzConfiguration.class)
public class BatchApplication {

    public static void main(String[] args) {
        SpringApplication.run(BatchApplication.class, args);
    }
}
错误日志

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.4.RELEASE)

2017-07-11 14:35:59.370  INFO 8868 --- [           main] com.schwab.cat.BatchApplication          : Starting BatchApplication on KVMOF0487DVLBDC with PID 8868 (started by pankaj.k.singh in C:\Users\pankaj.k.singh\Desktop\batch\sample hello world)
2017-07-11 14:35:59.377  INFO 8868 --- [           main] com.schwab.cat.BatchApplication          : No active profile set, falling back to default profiles: default
2017-07-11 14:35:59.511  INFO 8868 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@221af3c0: startup date [Tue Jul 11 14:35:59 IST 2017]; root of context hierarchy
2017-07-11 14:36:00.992  WARN 8868 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2017-07-11 14:36:01.013  WARN 8868 --- [           main] o.s.c.a.ConfigurationClassEnhancer       : @Bean method ScopeConfiguration.jobScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details.
2017-07-11 14:36:01.230  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:01.253  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$1bb5301] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:01.435  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:01.632  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSource' of type [org.apache.tomcat.jdbc.pool.DataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:01.641  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$$EnhancerBySpringCGLIB$$e3aef661] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:01.672  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'dataSourceInitializer' of type [org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:01.679  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration' of type [org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$$EnhancerBySpringCGLIB$$17e2d67] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:01.718  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'jobLauncher' of type [com.sun.proxy.$Proxy41] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:01.732  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'jobRegistry' of type [com.sun.proxy.$Proxy43] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:01.733  INFO 8868 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'com.quantvalley.batch.quartz.QuartzConfiguration' of type [com.quantvalley.batch.quartz.QuartzConfiguration$$EnhancerBySpringCGLIB$$88291ebb] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-11 14:36:03.256  INFO 8868 --- [           main] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: HSQL
2017-07-11 14:36:03.606  INFO 8868 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
2017-07-11 14:36:03.912  INFO 8868 --- [           main] org.quartz.impl.StdSchedulerFactory      : Using default implementation for ThreadExecutor
2017-07-11 14:36:03.980  INFO 8868 --- [           main] org.quartz.core.SchedulerSignalerImpl    : Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2017-07-11 14:36:03.984  INFO 8868 --- [           main] org.quartz.core.QuartzScheduler          : Quartz Scheduler v.2.2.3 created.
2017-07-11 14:36:03.987  INFO 8868 --- [           main] org.quartz.simpl.RAMJobStore             : RAMJobStore initialized.
2017-07-11 14:36:03.991  INFO 8868 --- [           main] org.quartz.core.QuartzScheduler          : Scheduler meta-data: Quartz Scheduler (v2.2.3) 'schedulerFactoryBean' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

2017-07-11 14:36:03.993  INFO 8868 --- [           main] org.quartz.impl.StdSchedulerFactory      : Quartz scheduler 'schedulerFactoryBean' initialized from an externally provided properties instance.
2017-07-11 14:36:03.993  INFO 8868 --- [           main] org.quartz.impl.StdSchedulerFactory      : Quartz scheduler version: 2.2.3
2017-07-11 14:36:03.998  INFO 8868 --- [           main] org.quartz.core.QuartzScheduler          : JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@20312893
2017-07-11 14:36:04.335  INFO 8868 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executing SQL script from class path resource [org/springframework/batch/core/schema-hsqldb.sql]
2017-07-11 14:36:04.366  INFO 8868 --- [           main] o.s.jdbc.datasource.init.ScriptUtils     : Executed SQL script from class path resource [org/springframework/batch/core/schema-hsqldb.sql] in 25 ms.
2017-07-11 14:36:04.733  INFO 8868 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-07-11 14:36:04.748  INFO 8868 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147483647
2017-07-11 14:36:04.749  INFO 8868 --- [           main] o.s.s.quartz.SchedulerFactoryBean        : Starting Quartz Scheduler now
2017-07-11 14:36:04.750  INFO 8868 --- [           main] org.quartz.core.QuartzScheduler          : Scheduler schedulerFactoryBean_$_NON_CLUSTERED started.
2017-07-11 14:36:04.773  INFO 8868 --- [           main] com.schwab.cat.BatchApplication          : Started BatchApplication in 6.481 seconds (JVM running for 11.417)
2017-07-11 14:36:20.039 ERROR 8868 --- [ryBean_Worker-1] c.q.batch.quartz.QuartzJobLauncher       : Encountered job execution exception!
2017-07-11 14:36:40.006 ERROR 8868 --- [ryBean_Worker-2] c.q.batch.quartz.QuartzJobLauncher       : Encountered job execution exception!
2017-07-11 14:37:00.001 ERROR 8868 --- [ryBean_Worker-3] c.q.batch.quartz.QuartzJobLauncher       : Encountered job execution exception!
2017-07-11 14:37:20.002 ERROR 8868 --- [ryBean_Worker-4] c.q.batch.quartz.QuartzJobLauncher       : Encountered job execution exception!
2017-07-11 14:37:40.002 ERROR 8868 --- [ryBean_Worker-5] c.q.batch.quartz.QuartzJobLauncher       : Encountered job execution exception!
2017-07-11 14:38:00.002 ERROR 8868 --- [ryBean_Worker-6] c.q.batch.quartz.QuartzJobLauncher       : Encountered job execution exception!

请有人调查一下,让我知道问题所在。

您在try/catch中吞下了异常,而只记录了异常发生的事实,而没有记录它是什么类型的异常。如果将日志记录语句更改为:

log.error("Encountered job execution exception!", e);
您将看到错误显示:

org.springframework.batch.core.launch.NoSuchJobException:未注册名为[Test\u job]的作业配置

您已经声明了一个名为
job1
的作业,而不是
Test\u job
的作业,因此您得到了异常。您必须将作业数据映射更改为:

map.put("jobName", "job1");
这将删除异常,但您的作业仍将运行一次,因为Spring批处理需要唯一的作业参数才能重新启动它,请参阅以获取解释。 因此,您必须将作业执行修改为以下内容(最简单的),以便能够持续运行:

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    try {
        Job job = jobLocator.getJob(jobName);
        Map<String, JobParameter> parametersMap = new HashMap<>();
        parametersMap.put("timestamp", new JobParameter(System.currentTimeMillis()));
        JobParameters jobParameters = new JobParameters(parametersMap);
        JobExecution jobExecution = jobLauncher.run(job, jobParameters);
        log.info("{}_{} was completed successfully", job.getName(), jobExecution.getId());
    } catch (Exception e) {
        log.error("Encountered job execution exception!", e);
    }
}
@覆盖
受保护的void executeInternal(JobExecutionContext上下文)引发JobExecutionException{
试一试{
Job Job=jobLocator.getJob(jobName);
Map参数Map=newhashmap();
参数map.put(“timestamp”,新作业参数(System.currentTimeMillis());
JobParameters JobParameters=新的JobParameters(参数映射);
JobExecution JobExecution=jobLauncher.run(作业,作业参数);
log.info(“{}{}已成功完成”,job.getName(),jobExecution.getId());
}捕获(例外e){
log.error(“遇到作业执行异常!”,e);
}
}