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

Turn @Path annotation into a CDI Stereotype #556

Open
glassfishrobot opened this issue Jun 6, 2017 · 8 comments
Open

Turn @Path annotation into a CDI Stereotype #556

glassfishrobot opened this issue Jun 6, 2017 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@glassfishrobot
Copy link

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.

@glassfishrobot
Copy link
Author

@mkarg mkarg added enhancement New feature or request annotations labels Feb 12, 2018
@mkarg
Copy link
Contributor

mkarg commented Apr 8, 2018

@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?

@arjantijms
Copy link
Contributor

Sure, and I'll discuss it with Ondrej if/when needed.

@arjantijms arjantijms self-assigned this Apr 8, 2018
@spericas
Copy link
Contributor

This should probably be a 3.0 issue given that CDI isn't mandatory now.

@ggam
Copy link
Contributor

ggam commented Apr 13, 2018 via email

@chkal
Copy link
Contributor

chkal commented Apr 14, 2018

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)?

@ggam
Copy link
Contributor

ggam commented Apr 14, 2018 via email

@chkal
Copy link
Contributor

chkal commented Apr 14, 2018

@ggam Oh, interesting. I didn't know about this before. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants