DI is not working properly on Job instances when scheduling quartz jobs programmatically
See original GitHub issueDescribe the bug When using job classes with programmatic job/triggers in quartz, fields annotated with @Inject gets injected, but with instances that have fields which have not been injected.
I discovered this problem when using a @ConfigProperty
field which had different values at different times. After elaborating, this also applies to @Inject ed fields.
Expected behavior Fields on injected beens in Job classes should also have their fields injected.
Actual behavior
Fields injected with @Inject
and @ConfigProperty
are null (or primitive default) when using a bean injected into a Job class.
To Reproduce https://github.com/lbroman/quarkus-config-bug
Run with
mvn test
Result will put out some log and you will find
2021-01-19 21:40:24,895 INFO [se.lbr.qua.JobScheduler] (main) Setting is: true
2021-01-19 21:40:24,915 DEBUG [se.lbr.qua.JobScheduler] (QuarkusQuartzScheduler_Worker-1) Setting is: false
JobScheduler is application scoped and setting is injected with @ConfigProperty. The value of the field is correct during init, but incorrect when accessed from quartz via the Job instance.
Environment (please complete the following information):
-
Output of
uname -a
orver
: MINGW64_NT-10.0-18362 BB904078 3.0.7-338.x86_64 2019-07-03 15:16 UTC x86_64 Msys -
Output of
java -version
: -
openjdk version “15” 2020-09-15 OpenJDK Runtime Environment (build 15+36-1562) OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)
-
GraalVM version (if different from Java): n/a
-
Quarkus version or git rev: tried 1.10.5.Final and 1.10.3.Final
-
Build tool (ie. output of
mvnw --version
orgradlew --version
): Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T17:06:16+02:00)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
FTR, as per @mkouba’s request (Zulip) I’ve verified this with Weld (CDI reference implementation) and I can confirm that it behaves equally.
Sorry for posting what was actually a support question as a bug. I would not have been able to figure this out myself. Thanks so much for the explanation!