I know that Stateless Session Beans refers to EJB beans while Request Scoped refer to CDI beans (or JSF managed beans), so I will start by giving their both definitions from the Java EE Tutoriel.
Stateless Session Beans definition:
A stateless session bean does not maintain a conversational state with the client. When a client invokes the methods of a stateless bean, the bean’s instance variables may contain a state specific to that client but only for the duration of the invocation. When the method is finished, the client-specific state should not be retained.
CDI Request Scoped definition:
A user’s interaction with a web application in a single HTTP request.
What I understood from both definitions is that the concept of stateless session beans is the same as the request scope concept, but I'm not realy sure because the naming "session" confused me. So, I asked my self if this were the case (same concept) maybe they would have a similar naming (using request instead of session).
So, my question is: Is there any conceptual difference between EJB stateless session beans and CDI/JSF request scoped beans?
There is a big difference.
A stateless EJB doesn't maintain state between invocations. It typically doesn't have state at all, except for dependencies on other beans. It offers a service to other components. The clients of a stateless bean can invoke it to serve an HTTP request, but they could also call it outside of any HTTP request (in a batch, a scheduled job, or whatever).
A request-scoped bean typically has a state (otherwise, it could be an application-scoped bean or a stateless bean). And this state lasts for the duration of an HTTP request. It can not be invoked outside of the HTTP request handling code. A good example for a request-scoped bean would be the current user:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With