Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [servlet-dev] Make Servlets CDI beans?

Hi,

On Tue, 7 Nov 2023 at 18:06, Emily Jiang via servlet-dev <servlet-dev@xxxxxxxxxxx> wrote:
Hi Arjan,

Further to our discussion on the platform call, I don't think making Servlet CDI Bean has much usage as I have not got any use case to say that you need to inject Servlet to another class. Please specify your use case if you have any.

The benefit of making Servlets a CDI bean is to have a more consistent platform without so many special cases.

Specifically, CDI beans automatically support a number of things, like obviously injection, but also interceptors, scopes, decorators, ability to be vetoed, and to programmatically enhance them in extensions with all those things.

It's a good point to raise that Servlets (within Jakarta EE) actually should support Interceptors, though I wonder if we have a TCK test for that anywhere?

Obviously when something is a CDI bean, you would not need to test that explicitly, as it comes automatically with being a CDI bean. In order to intercept the typical doGet() etc methods well, we would need to specify something additionally in a potential EE chapter of the Servlet spec. doGet() etc is now called by the Servlet Container's base class for Servlets directly, so it would never be intercepted. This would lead to surprises among users.

So to reiterate, very practical advantages of just being a true CDI bean are being able to give a Servlet a (custom) scope, decorators, ability to be vetoed and to programmatically add those things.

Kind regards,
Arjan Tijms

 

Based on the Jakarta EE platform spec, Servlet is a special Jakarta EE class and it supports the standard injection and interceptor. Your requirement for injection and interceptor support should be met though.
image.png
Thanks
Emily


On Tue, Nov 7, 2023 at 3:57 PM Arjan Tijms via servlet-dev <servlet-dev@xxxxxxxxxxx> wrote:
Hi,

This was discussed a while ago, but in the context of the CDI-centric Jakarta EE release it might be good to restart this discussion.

The overall goal of the Jakarta EE platform is to move the various spec specific component models and mechanisms to CDI (as per the "CDI-centric" theme).

Servlets have been @Inject injectable (loosely via the pruned Managed Beans spec, although the Servlet spec itself did not say so), but are themselves not CDI beans.

I'd like to propose to make Servlets officially CDI beans, but only within a Jakarta EE environment.

Meaning, Tomcat and Jetty would have no requirement to support this, and these requirements would be in a separate chapter of the Servlet spec.

Thoughts?

Kind regards,
Arjan Tijms
_______________________________________________
servlet-dev mailing list
servlet-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/servlet-dev


--
Thanks
Emily

_______________________________________________
servlet-dev mailing list
servlet-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/servlet-dev

Back to the top