On Jun 6, 2017, at 11:42 AM, Markus KARG <markus@...
Turning on CDI by default implies that all methods have to be non-final, which is not backwards compatible to JAX-RS 2.0. So we cannot do that.
That's a good point, and certainly not something we can easily resolve.
As others have mentioned, a strength of Java EE is integration with other specs like CDI, JSON-B, etc. But let us not forget that just as important is to ensure backward compatibility; adoption of newer versions of Java EE and JAX-RS depend on this compatibility not being threatened.
>> The only caveat is that the implementation will need to know the classes by that point, which is before ServletContainerInitializer is fired
that certainly is a problem, we do rely on servlet scanning..
Even it wouldn't be a problem, if @Path annotation isn't a bean defining annotation, the event wouldn't be fired at all in the "annotated" discovery mode if there are no other CDI beans (possible if resources only want to inject beans from other modules).
The approach of turning @Path into a stereotype is very nice and it doesn't require a runtime dependency on CDI at all. 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 along with @Path.
Furthermore, if @Path is a stereotype, it would also become a bean-defining annotation and turn on CDI by default, even if there are no other CDI beans in the module, which is what most people would expect.