我有一个Spring应用程序,该应用程序使用Quartz调度作业。它可以工作,但是当应用程序关闭时,我失去了所有工作。我想将这些作业持久保存到H2数据库(在本地文件中)。我的项目是用gradle构建的。我已经阅读了很多使用各种库的较旧版本构建的示例,但是要么无法使它们正常工作,要么无法在测试项目中复制它们。我阅读了一些看似有用的文档,并在application.properties中尝试了许多不同的设置,但我的应用仍使用内存作业存储中的默认设置启动。
在许多其他事情中,我研究了:
http://www.quartz-scheduler.org/documentation/quartz-2.1.7/configuration/ConfigJobStoreTX.html
http://www.quartz-scheduler.org/documentation/quartz-2.1.7/configuration/ConfigDataSources.html
https://dzone.com/articles/mule-quartz-connector-how-to-use-jdbc-jobstore-ins
https://www.candlepinproject.org/docs/candlepin/quartz_setup.html
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:file:~/testqrtz
spring.datasource.username=admin
spring.datasource.password=admin
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.h2.console.path=/h2
plugins {
id 'org.springframework.boot' version '2.2.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-quartz'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.h2database:h2'
}
触发器不持久。不会创建石英表。该项目继续使用默认作业存储。此消息在启动时显示:
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
我认为问题是,RAMJobStore
尽管OP显示已配置了JDBC存储,但为什么石英仍使用石英。
我认为答案是在该项目中用石英进行错误的弹簧集成。
显然,石英以某种默认方式(某种方式使用RAMJobStore
)以某种方式“启动” 。
application.properties
定义了所有属性的声音听起来更像是Spring Boot的配置文件,而不是Crystal的配置文件(通常称为quartz.properties)。
通常,您需要定义调度程序bean并指定您想从哪里确切读取配置:
@Bean
public SchedulerFactoryBean scheduler(Trigger trigger, JobDetail job, DataSource
quartzDataSource) {
SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
schedulerFactory.setConfigLocation(new ClassPathResource("quartz.properties"));
...
schedulerFactory.setJobDetails(job);
schedulerFactory.setTriggers(trigger);
schedulerFactory.setDataSource(quartzDataSource);
return schedulerFactory;
}
这是发生问题的可能原因之一,请在此处查找更多详细信息,并全面检查与石英的弹簧集成。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句