Skip to content

SchedulerFactoryBean no longer sets the job store's DataSource when the job store class has been customized #27709

Closed

Description

@wilkinsona

This is a regression in 5.3.13 caused by #27560. It was originally reported as a Spring Boot issue.

Activity

  1. sbrannen commented on Nov 20, 2021

    @sbrannen
    Member

    I agree that this is a regression in terms of effective behavior for the use case described in the Spring Boot issue; however, if the user was previously specifying org.quartz.impl.jdbcjobstore.JobStoreTX and actually wanted to use the JobStoreTX then the application was not working as expected, since Spring previously overrode JobStoreTX with LocalDataSourceJobStore.

    Thus, if the user wants to use JobStoreTX, they have to set the DataSource name. Whereas, if they are fine with using Spring's LocalDataSourceJobStore then they should never have specified JobStoreTX to begin with.

    I'm not saying we will not revert that the change (that's currently undecided). Rather, I'm pointing out that the user configuration for an explicit job store type was previously (silently) ignored.

    @jhoeller, thoughts?

  2. added
    in: coreIssues in core modules (aop, beans, core, context, expression)
    on Nov 20, 2021
  3. added this to the 5.3.14 milestone on Nov 22, 2021
  4. jhoeller commented on Nov 22, 2021

    @jhoeller
    Contributor

    From my perspective, let's put a corresponding note into the documentation.

    Allowing for custom variants of LocalDataSourceJobStore, picking up the SchedulerFactoryBean-configured DataSource in a custom implementation, was a worthwhile enhancement there in #27560. A specified JobStoreTX does not make sense since it will effectively get overridden with LocalDataSourceJobStore, so such a property entry should get removed entirely or replaced with a org.springframework.scheduling.quartz.LocalDataSourceJobStore value. In other words, I'm not really seeing a valid scenario for the previous dead-entry behavior, whereas the new behavior allows for customizations in advanced scenarios.

  5. roma2341 commented on Nov 24, 2021

    @roma2341

    From my perspective, let's put a corresponding note into the documentation.

    Allowing for custom variants of LocalDataSourceJobStore, picking up the SchedulerFactoryBean-configured DataSource in a custom implementation, was a worthwhile enhancement there in #27560. A specified JobStoreTX does not make sense since it will effectively get overridden with LocalDataSourceJobStore, so such a property entry should get removed entirely or replaced with a org.springframework.scheduling.quartz.LocalDataSourceJobStore value. In other words, I'm not really seeing a valid scenario for the previous dead-entry behavior, whereas the new behavior allows for customizations in advanced scenarios.

    New behaviour is very confusing. I have updated spring-boot-starter-parent and couldn't run my project for several hours because "DataSource name not set" message appeared (And nothing that could help solve the issue). So, maybe this message should be more clear.

  6. wxz0107 commented on Dec 8, 2021

    @wxz0107

    org.quartz.jobStore.class=org.springframework.scheduling.quartz.LocalDataSourceJobStore

  7. smpshehan commented on Dec 8, 2021

    @smpshehan

    @wxz0107 Will that fix the problem? Will it get the spring.datasource as the quartz data source?

  8. wxz0107 commented on Dec 8, 2021

    @wxz0107

    @wxz0107 Will that fix the problem? Will it get the spring.datasource as the quartz data source?

    yes,i use springboot 2.5.7, it work by this configuration

  9. smpshehan commented on Dec 8, 2021

    @smpshehan

    Oki, I upgraded to Springboot 2.6.1 and it was failing due to the same error.
    So with org.quartz.jobStore.class=org.springframework.scheduling.quartz.LocalDataSourceJobStore
    I can start up the springboot app successfully. Now I need to verify that it works as before. Thanks for your suggestion.

  10. wsdng commented on Dec 8, 2021

    @wsdng

    I had the same problem when upgrading from Spring Boot 2.5.6 to 2.6.1.
    Using LocalDataSourceJobStore is not an option because in my case the JobStore needs to be clustered.
    I've been using the Annotation @QuartzDataSource to identify the dataSource.
    When I got an error that the dataSource name is not set, I've added the name by setting property
    "spring.quartz.properties.org.quartz.jobStore.dataSource"
    This did not solve the problem, because now I got an Exception "There is no DataSource named '...'" although the dataSource bean had been instantiated at this point.
    As I understand from the conversation above, there is a workaround to get things right. I would appreciate some more details on this.

  11. smpshehan commented on Dec 8, 2021

    @smpshehan

    I use it clustered too.
    org.quartz.jobStore.class=org.springframework.scheduling.quartz.LocalDataSourceJobStore
    Should take the current spring data source configuration as the jdbc jobStore. That is what I believe.

  12. wsdng commented on Dec 9, 2021

    @wsdng

    I've got it running now. I still have the jobStore properties isClustered and driverDelegateClass in place but removed the jobStore.class.

    The thing that confused me in the first place was the Quartz documentation for clustering:
    "Clustering currently only works with the JDBC-Jobstore (JobStoreTX or JobStoreCMT)". I did not recognize that LocalDataSourceJobStore was a class provided by spring as a replacement for JobStoreTX and JobStoreCMT.
    Thank you for the clarification.

  13. self-assigned this
    on Dec 14, 2021
  14. added a commit that references this issue on Dec 14, 2021
    d7b9270
  15. dmytro-dobrovolskyi commented on Oct 20, 2022

    @dmytro-dobrovolskyi

    Spent a lot of time on this... Apparently, if you want @QuartzDataSource to work you need to make your other dataSource (if you have one) as @Primary which is kinda implied in javadoc but it is not clear that you really have to mark it as primary.

  16. jeoningu commented on Feb 2, 2023

    @jeoningu

    I modified the QuartzConfiguration file and it works normally. Why is that?

    1. remove @EnableAutoConfiguration, @QuartzDataSource
    2. change the quartzDataSource method name to aa and set it to @bean (name="aa")

    It's my opinion!

    1. DataSource objects are registered as spring beans even without @EnableAutoConfiguration

    2. Even if there is no @QuartzDataSource and the spring bean name is not quartzDataSource, by some internal action Quartz JobStore finds the dataSource spring bean and makes a db connection

    If my opinion is correct, can you explain the inner action of number 2 in detail?

  17. shaikahmadbasha commented on Mar 23, 2025

    @shaikahmadbasha

    Just leaving a note here for anyone integrating Quartz for the first time.
    I was trying to do a simple demo of Spring Boot with Quartz and ran into issues making it clustered. When using JobStoreTx, I got a 'DataSource not found' error. On the other hand using LocalDataSourceJobStore did not create a clustered setup. After some trial and error, I realized that setting the instanceId is crucial. Setting instanceId to AUTO made it work with LocalDataSourceJobStore.

    A simple config looks like:
    spring: quartz: job-store-type: jdbc properties: org: quartz: scheduler: instanceName: QuartzScheduler instanceId: AUTO jobStore: class: org.springframework.scheduling.quartz.LocalDataSourceJobStore driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate tablePrefix: QRTZ_ isClustered: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: documentationA documentation task

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions