如何在石英调度中设置数据源。

这是我的配置文件 quartz.properties


org.quartz.scheduler.instanceName= LivingOrdering

org.quartz.scheduler.instanceId=99199

org.quartz.scheduler.rmi.export=false

org.quartz.scheduler.rmi.proxy=false

org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool

org.quartz.threadPool.threadCount=3

org.quartz.context.key.QuartzTopic=QuartzPorperties

org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX

org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate

org.quartz.jobStore.tablePrefix=qrtz_

org.quartz.jobStore.dataSource=quartzDataSource

org.quartz.dataSource.quartzDataSource.driver=org.postgresql.Driver

org.quartz.dataSource.quartzDataSource.URL=jdbc:postgresql://localhost:5432/quartz

org.quartz.dataSource.quartzDataSource.user=admin

org.quartz.dataSource.quartzDataSource.password=admin

org.quartz.dataSource.quartzDataSource.maxConnections=300

我在行中收到错误 - :


Scheduler scheduler = new StdSchedulerFactory().getScheduler();

Error: org.quartz.SchedulerException: Could not initialize DataSource: quartzDataSource


达令说
浏览 125回答 4
4回答

月关宝盒

SpringBoot 有 Quartz 自动配置,你不需要使用 quartz.properties 配置 Quartz,因为它对 Spring 一无所知,所以你不能只把数据源名称放在那里。阅读文档。开始使用 Quartz 所需要做的就是在 pom.xml 中包含 starter:<dependency> &nbsp;&nbsp;&nbsp;&nbsp;<groupId>org.springframework.boot</groupId> &nbsp;&nbsp;&nbsp;&nbsp;<artifactId>spring-boot-starter-quartz</artifactId> </dependency>配置您的标准 Spring 数据源(application.properties):spring.datasource.url&nbsp;=&nbsp;jdbc:postgresql://localhost:5432/quartzspring.datasource.username&nbsp;=&nbsp;admin spring.datasource.password&nbsp;=&nbsp;admin然后添加(在 application.properties 中):spring.quartz.job-store-type=jdbc #&nbsp;Add&nbsp;the&nbsp;below&nbsp;line&nbsp;to&nbsp;have&nbsp;Spring&nbsp;Boot&nbsp;auto&nbsp;create&nbsp;the&nbsp;Quartz&nbsp;tables spring.quartz.jdbc.initialize-schema=always如果你想将额外的属性传递给 Quartz,你可以spring.quartz.properties像这样在属性名前面加上前缀:spring.quartz.properties.org.quartz.scheduler.instanceName=LivingOrdering

慕莱坞森

从 application.properties 文件中删除 spring.datasource.* 并spring.datasource.name= quartzDataSource&nbsp;为我添加作品。你可能还需要配置你org.quartz.dataSource.quartzDataSource.provider的(hikaricp 或 c3po-default)

慕桂英4014372

我知道这个问题很老了,但由于我最终来到这里寻找解决方案,而且不清楚该怎么做,所以我会为仍在寻找解决方案的其他人提供我的解决方案。项目配置:JDK:18.0.1Maven:3.6.3Spring boot:2.7.4Quartz:spring-boot-starter-quartz如果你想为你的应用程序和 quartz 使用单个数据源,则以下配置有效。例如,我将它用于测试。spring:&nbsp; datasource:&nbsp; &nbsp; url: jdbc:h2:mem:db;DB_CLOSE_DELAY=-1&nbsp; &nbsp; driverClassName: org.h2.Driver&nbsp; &nbsp; username: sa&nbsp; &nbsp; password: sa&nbsp; quartz:&nbsp; &nbsp; job-store-type: jdbc&nbsp; &nbsp; jdbc:&nbsp; &nbsp; &nbsp; initialize-schema: never&nbsp; &nbsp; properties:&nbsp; &nbsp; &nbsp; org:&nbsp; &nbsp; &nbsp; &nbsp; quartz:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobStore:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; class: org.springframework.scheduling.quartz.LocalDataSourceJobStore&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablePrefix: TB_PR_QRTZ_也不要忘记使用@QuartzDatasource 标记您的数据源bean。@Primary@Bean@QuartzDataSource@ConfigurationProperties(prefix = "spring.datasource")public DataSource defaultDatasource (){&nbsp; &nbsp; return DataSourceBuilder.create().build();}但是,如果您需要 2 个数据源,则必须在 spring.quartz.properties.org.quartz.dataSource 中指定自定义数据源这是我的应用程序配置spring:&nbsp; datasource:&nbsp; &nbsp; byq:&nbsp; &nbsp; &nbsp; url: jdbc:oracle:thin:@//app-db/schema-name&nbsp; &nbsp; &nbsp; driverClassName: oracle.jdbc.OracleDriver&nbsp; &nbsp; &nbsp; username: ZZZ&nbsp; &nbsp; &nbsp; password: XXX&nbsp; quartz:&nbsp; &nbsp; job-store-type: jdbc&nbsp; &nbsp; wait-for-jobs-to-complete-on-shutdown: true&nbsp; &nbsp; jdbc:&nbsp; &nbsp; &nbsp; initialize-schema: never&nbsp; &nbsp; properties:&nbsp; &nbsp; &nbsp; org:&nbsp; &nbsp; &nbsp; &nbsp; quartz:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataSource:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; quartzDataSource:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; URL: jdbc:postgresql://scheduler-db/scheduler&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; driver: org.postgresql.Driver&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user: ZZZ&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; password: XXX&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobStore:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataSource: quartzDataSource&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; class: org.quartz.impl.jdbcjobstore.JobStoreTX&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tablePrefix: TB_QRTZ_

倚天杖

请注意,在quartz.properties文件中,属性名称以org.quartz...;开头&nbsp;对于更高版本的石英(如果我没记错的话,在 2.5.6 之后)它们以spring.quartz.properties.org.quartz....当我将 SpringBoot 版本从 2.1.2 更新到 2.6.3(包括 quartz 库)时遇到了这个问题,错误与这个帖子问题中的错误相同。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java