Breadcrumb

  • Creating and Using Contexts and Dependency Injection (CDI) Interceptors

    Contexts and Dependency Injection (CDI) was introduced with Java Platform, Enterprise Edition (Java EE) 6 as JSR-299. The Contexts part of CDI allows beans to share and participate in the life cycle of another bean, while the Dependency Injection part of CDI allows beans to get a reference to an instance of another bean simply by injecting it. CDI power is the ability to loosely couple classes by removing the instantiation process and simultaneously enforcing strong-type checking. CDI provides an @Inject annotation to create a reference to another bean (avoiding the older context lookup process). CDI enforces typing by eliminating string-based lookup so that the compiler can detect errors. CDI works very well with integrated development environments (IDEs).

    This tutorial looks at a particular kind of CDI service called an interceptor. An interceptor is invoked prior to the invocation of a method on which the interceptor binding annotation is placed. Interceptors are very useful for tasks that need to be applied to several methods without adding more code to the existing methods. These tasks are often referred to as cross-cutting tasks. Logging and auditing are examples of tasks that cut across business methods,

    In this tutorial, you create an interceptor binding type, which is an annotation used to associate an interceptor with either a method or a bean class. The interceptor binding type is also associated with an interceptor class that contains a single method annotated with @AroundInvoke.

    Duration: 45 minutes

    Release Date: 14-JAN-2013

Create a Review

Be the first to create a review for this content item!

Buttons