'quarkus with @NoScope like @Stateless?
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;
}
Solution 1:[1]
CDI @RequestScoped
means new instance for each request. It's not keeping the state between requests so you can think it as a replacement for @Stateless
.
Solution 2:[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.
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Marek ?ylicz |
Solution 3 | Tim Brückner |