0

What is the quarkus counterpart of a @Stateless EJB?

Actually, I can only make use of cdi within typical cdi beans, but there is no bean with no scope like @Stateless in quarkus, or?

@NoScope // such scope does actually not exit in cdi or quarkus
public class MyBean{

    @Inject 
    EntityManager em;

}
nimo23
  • 5,170
  • 10
  • 46
  • 75
  • I don't really understand what you mean by `@NoScope` or "scope like `@Stateless`", but I _guess_ that `@Dependent` might be what you're looking for. – Ladicek Dec 10 '19 at 17:06
  • But `@Dependend` inherits the scope of its injected parent bean. `@Stateless` has **no scope** and I can also use `@Inject` within this bean. – nimo23 Dec 10 '19 at 17:14
  • Ah, OK. I didn't understand your question. I don't have an answer. Perhaps if you could share your motivation / use case, that would help other potential responders. – Ladicek Dec 10 '19 at 18:39
  • Use case is: make a class a bean to consume cdi without binding it to a scope so that this `@NoScoped` bean can also `@Inject` something..with `@Stateless` it would be possible..but quarkus or cdi does not have something like `@Stateless`, or? – nimo23 Dec 10 '19 at 18:42

3 Answers3

4

CDI @RequestScopedmeans new instance for each request. It's not keeping the state between requests so you can think it as a replacement for @Stateless.

@Stateless vs @RequestScoped

Panu Haaramo
  • 2,932
  • 19
  • 41
2

When we use @RequestScope in a context where we would use @Stateless, we only simulate @Stateless behavior by destroying and creating the bean on every request. The benefit is we enforce isolation between requests; however, the tradeoff is we perform expensive creation / destroying of the bean every request.

If we care about performance and only need stateless behavior without enforcing isolation between requests, we should design our beans as stateless and use @Dependent or @ApplicationScoped scopes. There is no risk of having no isolation between requests if developers are careful and write their code statelessly.

Using @RequestScope as @Stateless sounds like a smelly workaround for a missing feature in the framework; hence I prefer not to use it in this context unless necessary.

Marek Żylicz
  • 429
  • 3
  • 8
0

EJBs come with additional features like thread pooling, monitoring, or transaction management (when container managed),...

So in Quarkus there is no direct replacement for @Stateless, but you can get close by using @Transactional in combination with @RequestScoped.

I don't know @NoScope, but I guess you meant @Dependent.

Check out Adam Bien's blog: https://www.adam-bien.com/roller/abien/entry/migration_from_stateless_bce_to

Tim Brückner
  • 1,928
  • 2
  • 16
  • 27