-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
@Scheduled not found when in parent classes #38781
Comments
/cc @mkouba (scheduler) |
Well, I don't remember all the details but we initially decided not to support the inheritance of It would definitely make the discovery and validation more complex. Also if there are multiple subclasses inheriting a scheduled method from a superclass you wouldn't be able to declare the As a workaround, you can override the scheduled method in the subclass ( |
Yeah I had just thought of that workaround and thats most likely what I'll do. I don't really know the history as to why it was excluded, but I'm sure there are pros/cons on each side of including it or not. I was just surprised that it didn't work and spent half a day trying to figure out why my code wasn't working. If it isn't going to be supported in parent classes, maybe that should be called out in the docs? |
That's a good idea. Actually, we can also detect the case where a |
Hm, actually it is documented in the reference guide - there is a warning that starts with text "Subclasses never inherit the metadata of a So I will:
|
- turn the warning in the docs into a subsection - mention the inheritance rules in the javadoc of the Scheduled annotation - fail the build if an abstract class/interface declares a method annotated with Scheduled - add support for static interface scheduled methods (so far only static methods declared on a class were supported) - fixes quarkusio#38781
Is it just when declared on a method of an abstract class? Or anywhere in the parent class hierarchy? |
An abstract class or an interface. A superclass that is not abstract might be a legal use case. |
Thanks very much @mkouba for your help! |
Describe the bug
When using the
@Scheduled
annotation on a method, it is not found/picked up when the scheduled method is on a parent class of a CDI bean.Expected behavior
I would expect any
@Scheduled
method in the class hierarchy of a CDI bean to be found and executed.Actual behavior
Only
@Scheduled
methods within the top-level class of a CDI bean are found/executedHow to Reproduce?
BeanWithScheduled
which is simple CDI bean with an@Scheduled
method.ChildBean
which has an@Scheduled
method and also extends a base class,SubclassWithScheduled
.SubclassWithScheduled
also has an@Scheduled
method../mvnw clean quarkus:dev
@Scheduled
methods in theBeanWithScheduled
andChildBean
classes were executed. The@Scheduled
method in theSubclassWithScheduled
base class was not executed.Output of
uname -a
orver
Darwin edeandrea-m1pro 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64
Output of
java -version
Quarkus version or git rev
3.7.2
Build tool (ie. output of
mvnw --version
orgradlew --version
)Additional information
No response
The text was updated successfully, but these errors were encountered: