EJB/CDI shared Aspects
As I’ve been working through the CDI TCK, and Emil and Reza are working through the EJB TCK, we’re seeing the same shared capabilities for both kinds of beans. Both CDI beans and EJB beans have the same aspects, which makes sense because they have the same cross-cutting concerns.
Conceptually, the aspects are all designed out of @Interceptors, which CDI/EJB supports in two flavors: EJB’s direct naming of the interceptor classes, and CDI’s declarative description using the @InterceptorBinding. CDI’s bindings are a bit more descriptive because your code says what it wants to do, named by the custom binding, not who is responsible for doing it like the EJB interceptor class.
In Resin, we’ve added the EJB custom aspects to any CDI bean, i.e. essentially any Java class, including servlets, filters, and JSF beans. The predefined aspects in EJB are:
- transaction boundaries: @TransactionAttribute
- security: @RolesAllowed, @RunAs
- async/messaging: @Asynchronous
- locks: @Lock
- and the custom @Interceptors and @Decorators
Tags: cdi, ejb, web profile
