Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wilkinsona opened this issue Nov 20, 2021 · 12 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: documentation A documentation task
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented Nov 20, 2021

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

@sbrannen
Copy link
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?

@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 20, 2021
@jhoeller jhoeller added this to the 5.3.14 milestone Nov 22, 2021
@jhoeller
Copy link
Contributor

jhoeller commented Nov 22, 2021

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.

@jhoeller jhoeller added type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 22, 2021
@roma2341
Copy link

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.

@wxz0107
Copy link

wxz0107 commented Dec 8, 2021

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

@smpshehan
Copy link

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

@wxz0107
Copy link

wxz0107 commented Dec 8, 2021

@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

@smpshehan
Copy link

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.

@wsdng
Copy link

wsdng commented Dec 8, 2021

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.

@smpshehan
Copy link

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.

@wsdng
Copy link

wsdng commented Dec 9, 2021

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.

@dmytro-dobrovolskyi
Copy link

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.

@jeoningu
Copy link

jeoningu commented Feb 2, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

10 participants