Quartz 调度程序未启动

发布于 2025-01-16 05:59:31 字数 3369 浏览 2 评论 0原文

我正在创建一个使用 Quartz 的 Spring Boot 应用程序,这是我的quartz.yaml 文件,

org:
  quartz:
    dataSource:
      mySql:
        maxIdleTime: '60'
        idleConnectionValidationSeconds: '50'
        password: test2
        user: test2
        URL: jdbc:mysql://localhost:3306/schedules?useSSL=false
        driver: com.mysql.jdbc.Driver
        maxConnections: '10'
        validationQuery: select 0 from dual
    plugin:
      jobHistory:
        class: org.quartz.plugins.history.LoggingJobHistoryPlugin
        jobToBeFiredMessage: 'Job [{1}.{0}] to be fired by trigger [{4}.{3}], re-fire:
          {7}'
        jobFailedMessage: 'Job [{1}.{0}] execution failed with exception: {8}'
        jobWasVetoedMessage: 'Job [{1}.{0}] was vetoed. It was to be fired by trigger
          [{4}.{3}] at: {2, date, dd-MM-yyyy HH:mm:ss.SSS}'
        jobSuccessMessage: 'Job [{1}.{0}] execution complete and reports: {8}'
      triggerHistory:
        class: org.quartz.plugins.history.LoggingTriggerHistoryPlugin
        triggerFiredMessage: 'Trigger [{1}.{0}] fired job [{6}.{5}] scheduled at:
          {2, date, dd-MM-yyyy HH:mm:ss.SSS}, next scheduled at: {3, date, dd-MM-yyyy
          HH:mm:ss.SSS}'
        triggerCompleteMessage: 'Trigger [{1}.{0}] completed firing job [{6}.{5}]
          with resulting trigger instruction code: {9}. Next scheduled at: {3, date,
          dd-MM-yyyy HH:mm:ss.SSS}'
        triggerMisfiredMessage: 'Trigger [{1}.{0}] misfired job [{6}.{5}]. Should
          have fired at: {3, date, dd-MM-yyyy HH:mm:ss.SSS}'
    jobStore:
      maxMisfiresToHandleAtATime: '10'
      dataSource: mySql
      isClustered: 'false'
      class: org.quartz.impl.jdbcjobstore.JobStoreTX
      useProperties: 'true'
      misfireThreshold: '60000'
      driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
      tablePrefix: QRTZ_
    threadPool:
      threadPriority: '5'
      class: org.quartz.simpl.SimpleThreadPool
      threadCount: '4'
    scheduler:
      instanceId: AUTO
      instanceName: SampleJobScheduler
      idleWaitTime: '10000'

我正在尝试使用 SQL 数据库,但它使用 ram。这是我收到的错误

调度程序类:'org.quartz.core.QuartzScheduler' - 正在运行 本地。未开始。目前处于待机模式。职位数量 执行:0 使用线程池“org.quartz.simpl.SimpleThreadPool”- 有 10 个线程。使用作业存储“org.quartz.simpl.RAMJobStore”- 这不支持持久化。并且不是聚类的。

这是我的配置

@Configuration
public class Config {

  @Value("${library.file-path.quartz}")
  Resource quartsPath;

  @Autowired private ApplicationContext applicationContext;

  @Bean
  public SchedulerFactoryBean scheduler(JobFactory factory) throws IOException {
    SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
    schedulerFactory.setQuartzProperties(quartzProperties());
    schedulerFactory.setJobFactory(factory);
    return schedulerFactory;
  }

  @Bean
  public SpringBeanJobFactory springBeanJobFactory() {
    AutoWiringSpringBeanJobFactory jobFactory = new AutoWiringSpringBeanJobFactory();
    jobFactory.setApplicationContext(applicationContext);
    return jobFactory;
  }

  public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(quartsPath);
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
  }
}

I am creating a spring boot application that is using Quartz this is my quartz.yaml file

org:
  quartz:
    dataSource:
      mySql:
        maxIdleTime: '60'
        idleConnectionValidationSeconds: '50'
        password: test2
        user: test2
        URL: jdbc:mysql://localhost:3306/schedules?useSSL=false
        driver: com.mysql.jdbc.Driver
        maxConnections: '10'
        validationQuery: select 0 from dual
    plugin:
      jobHistory:
        class: org.quartz.plugins.history.LoggingJobHistoryPlugin
        jobToBeFiredMessage: 'Job [{1}.{0}] to be fired by trigger [{4}.{3}], re-fire:
          {7}'
        jobFailedMessage: 'Job [{1}.{0}] execution failed with exception: {8}'
        jobWasVetoedMessage: 'Job [{1}.{0}] was vetoed. It was to be fired by trigger
          [{4}.{3}] at: {2, date, dd-MM-yyyy HH:mm:ss.SSS}'
        jobSuccessMessage: 'Job [{1}.{0}] execution complete and reports: {8}'
      triggerHistory:
        class: org.quartz.plugins.history.LoggingTriggerHistoryPlugin
        triggerFiredMessage: 'Trigger [{1}.{0}] fired job [{6}.{5}] scheduled at:
          {2, date, dd-MM-yyyy HH:mm:ss.SSS}, next scheduled at: {3, date, dd-MM-yyyy
          HH:mm:ss.SSS}'
        triggerCompleteMessage: 'Trigger [{1}.{0}] completed firing job [{6}.{5}]
          with resulting trigger instruction code: {9}. Next scheduled at: {3, date,
          dd-MM-yyyy HH:mm:ss.SSS}'
        triggerMisfiredMessage: 'Trigger [{1}.{0}] misfired job [{6}.{5}]. Should
          have fired at: {3, date, dd-MM-yyyy HH:mm:ss.SSS}'
    jobStore:
      maxMisfiresToHandleAtATime: '10'
      dataSource: mySql
      isClustered: 'false'
      class: org.quartz.impl.jdbcjobstore.JobStoreTX
      useProperties: 'true'
      misfireThreshold: '60000'
      driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
      tablePrefix: QRTZ_
    threadPool:
      threadPriority: '5'
      class: org.quartz.simpl.SimpleThreadPool
      threadCount: '4'
    scheduler:
      instanceId: AUTO
      instanceName: SampleJobScheduler
      idleWaitTime: '10000'

I am trying to use SQL database but its uses ram. This is the error I am getting

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.

This is my Configuration

@Configuration
public class Config {

  @Value("${library.file-path.quartz}")
  Resource quartsPath;

  @Autowired private ApplicationContext applicationContext;

  @Bean
  public SchedulerFactoryBean scheduler(JobFactory factory) throws IOException {
    SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
    schedulerFactory.setQuartzProperties(quartzProperties());
    schedulerFactory.setJobFactory(factory);
    return schedulerFactory;
  }

  @Bean
  public SpringBeanJobFactory springBeanJobFactory() {
    AutoWiringSpringBeanJobFactory jobFactory = new AutoWiringSpringBeanJobFactory();
    jobFactory.setApplicationContext(applicationContext);
    return jobFactory;
  }

  public Properties quartzProperties() throws IOException {
    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(quartsPath);
    propertiesFactoryBean.afterPropertiesSet();
    return propertiesFactoryBean.getObject();
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌面超妹 2025-01-23 05:59:31

我可以在 SchedulerFactoryBean 中设置数据源。
dataSource 是应用程序使用的 DataSource,并由 Spring 在该配置类中注入:

@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setJobFactory(springBeanJobFactory());
    factory.setQuartzProperties(quartzProperties());
    factory.setDataSource(dataSource);
    return factory;
}

I got it working setting the datasource in SchedulerFactoryBean.
dataSource is the DataSource used by the application and inyected by Spring in this configuration class:

@Bean
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
    SchedulerFactoryBean factory = new SchedulerFactoryBean();
    factory.setJobFactory(springBeanJobFactory());
    factory.setQuartzProperties(quartzProperties());
    factory.setDataSource(dataSource);
    return factory;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文