-
Notifications
You must be signed in to change notification settings - Fork 121
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
Turn @Path annotation into a CDI Stereotype #556
Comments
|
@arjantijms As this was originally opened by @OndrejM, may I assign this issue to you so you can further drive this item in his name? |
Sure, and I'll discuss it with Ondrej if/when needed. |
This should probably be a 3.0 issue given that CDI isn't mandatory now. |
CDI integration is one of those changes that affect most people, and I
still think it can be done in a minor revision.
Annotating a class at compile time doesn't make the the annotation required
on the classpath at runtime (the JVM just ignores it) so we could find a
solution that works without mandating CDI.
Another possibility is for implementors to register the resources as beans
via a CDI extension. Extensions are loaded by CDI so they wouldn't be
loaded if CDI is not on the classpath. (This approach is not always
feasible though as you need to know the classes before
ServletContainerInitializers are called, which is not the case of Jersey
AFAIK).
JAX-RS 2.1 specified that managed executor services must be used in case
the runtime supports JSR-236. The same can be done here without pulling a
runtime dependency on CDI.
El vie., 13 abr. 2018 16:05, Santiago Pericas-Geertsen <
notifications@github.com> escribió:
… This should probably be a 3.0 issue given that CDI isn't mandatory now.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#556 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACAucEhHUdigUDComxgaBfxyBIJYshRUks5toLCTgaJpZM4TLt7I>
.
|
Is this the case even for |
Yes, although it's a little known behavior. See this Stackoverflow
questions for some more details:
https://stackoverflow.com/questions/3567413/why-doesnt-a-missing-annotation-cause-a-classnotfoundexception-at-runtime
El sáb., 14 abr. 2018 10:58, Christian Kaltepoth <notifications@github.com>
escribió:
… Annotating a class at compile time doesn't make the the annotation required
on the classpath at runtime (the JVM just ignores it) so we could find a
solution that works without mandating CDI.
Is this the case even for @retention(RUNTIME)?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#556 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACAucK0uVGLOppzKo9hUkCO4pjmAsCOAks5tobo2gaJpZM4TLt7I>
.
|
@ggam Oh, interesting. I didn't know about this before. Thanks. |
As suggested on the mailing list here and here.
This is a sub-issue of #60.
In order to turn any resource class annotated with
@Path
into a CDI bean, the@Path
annotation can be turned into a CDI Stereotype with the@RequestScoped
scope default. This doesn't require a runtime dependency on CDI at all and wouldn't introduce any changes to JAX-RS API or implementations outside of a CDI container.CDI API would be needed only to compile JAX-RS API because annotations not found on the classpath are ignored by the JVM, CDI impl wouldn't be needed at all. If we specify @RequestScoped in the stereotype, it would just specify what I believe all implementations do anyway -> create a resource instance per request, which is the default behavior mandated by the previous JAX-RS 2.0
It would be possible to override the scope for each class in a standard way by providing a scope annotation together with
@Path
.Furthermore, if
@Path
is a stereotype, it would also become a bean-defining annotation and turn on CDI scanning for the module by default, even if there are no other CDI beans in the module, which is what most people would expect. Again, outside of a CDI container, the additional annotations on the@Path
annotation would be ignored. They can even be missing in the classpath at runtime and would still be just ignored without any errors.The text was updated successfully, but these errors were encountered: