question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Quartz cannot find bean instances of jobs

See original GitHub issue

Describe the bug

Hello there,

we have an issue that is present with quarkus 1.13 - 2.0.2, in 1.12 the issue is not yet present.

In our setup we are using quartz to schedule the execution of jobs. Here is a simple implementation example of one of our jobs:

@Startup
@Singleton
class HouseKeepingJob(
  scheduler: Scheduler,
  jobRepository: JobRepository,
  @ConfigProperty(name = "job.timeout") private val timeout: Long,
) : BaseJob(
  jobRepository = jobRepository,
  scheduler = scheduler,
) {

  override fun execute() {
    // implementation details
  }

  override fun getCron() {
    // implementation details
  }
}

class BaseJob(
  scheduler: Scheduler,
  jobRepository: JobRepository,
) {
  init {
    val job = JobBuilder.newJob(this::class.java).build()
    val trigger: Trigger = TriggerBuilder.newTrigger()
      .withSchedule(CronScheduleBuilder.cronSchedule(getCron()))
      .build()

    scheduler.scheduleJob(job, trigger)
  }

  abstract fun getCron(): String
}

As you can see in the above example, we are creating a Singleton instance of our job which should be used by quartz. With quarkus 1.12.x, this is working perfectly fine. From 1.13.x above, we have the issue that in the InvokerJobFactory deep inside quarkus-quartz, the singleton instance of our job cannot be resolved anymore, therefore a fallback is used (SimpleJobFactory) which fails due to a missing no-args constructor on our job. We have found that the jobClass used for bean resolving differs between 1.12 and 1.13 - while in 1.12 the jobClass would be HouseKeepingJob in 1.13 it is HouseKeepingJob_SubClass, which is the only major difference we were able to spot. In the migration guide we cannot find any info concerning such a change. Can you please help us understand what changed and what the best course of action is for us right now?

Thanks

Expected behavior

the singleton instance of our job should still be discoverable in 1.13

Actual behavior

the singleton instance of our job is not discoverable anymore since 1.13

How to Reproduce?

No response

Output of uname -a or ver

Darwin 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 arm64

Output of java -version

openjdk version “11.0.9.1” 2020-11-04 LTS OpenJDK Runtime Environment Zulu11.43+1021-CA (build 11.0.9.1+1-LTS) OpenJDK 64-Bit Server VM Zulu11.43+1021-CA (build 11.0.9.1+1-LTS, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

1.13.7

Build tool (ie. output of mvnw --version or gradlew --version)

gradle 6.7.1

Additional information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
ferencbeutel4711commented, Jul 22, 2021

hey guys, thank you so much for the quick fix and great work in general on this issue, it is much appreciated 😃

3reactions
mkoubacommented, Jul 22, 2021

I’ve just sent a PR - you can mimic this logic as a workaround.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring cannot inject Bean in class that implements Quartz Job
You will want to use the spring helpers/implementations of the various Quartz components, so that the jobs you create will be managed by ......
Read more >
How to Inject Spring Beans into Quartz Jobs - HowToDoInJava
The solution is to inject Spring's ApplicationContext instance to org.quartz.SchedulerContext which is available using org.quartz.
Read more >
How to Schedule Jobs With Quartz in Spring Boot - HackerNoon
JobDetails defines Job instances and data that are related to it. Trigger describes the schedule of job execution. Scheduler is the main Quartz...
Read more >
Accessing Spring beans from Quartz jobs | by Rahul Agarwal
executed. Our bean is named in the jobClass property. --> <bean name="myJob" class="org.springframework.scheduling.
Read more >
Guide to Quartz with Spring Boot - Job Scheduling and ...
Quartz is an open-source, heavily featured job-scheduling ... and the SchedulerContext as bean property values, whereas Job doesn't.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found