This multi-part series introduces you to the Java EE 6 Contexts and Dependency Injection feature.
Release Date: 22-JAN-2013
Created by: Tom McGinn, Paromita Dutta, and Miguel Salazar
This is the Japanese translation of this tutorial (English version). This tutorial shows the basics of Contexts and Dependency Injection (CDI) for Java EE 6 by developing a sign-up form that uses servlets to process its data and inject Java beans.
Contexts and Dependency Injection (CDI) is a new feature in Java EE 6 that defines a powerful and type-safe Dependency Injection using “contextual” references or scopes. Based on the JSR-299 specification, CDI supplies a set of services that allow Java EE components (such as EJB session beans and JavaServer Faces managed beans) to be bound to lifecycle contexts. These components can then be injected and interact in a loosely coupled way by firing and observing events. The contextual nature of CDI allows the use of beans from different scopes to be more natural and convenient.
Duration: 60 minutes
This tutorial shows the basics of Contexts and Dependency Injection (CDI) for Java EE 6 by developing a sign-up form that uses servlets to process its data and inject Java beans.
Events are an important part of the JavaBeans model. You have probably used events in Abstract Windowing Toolkit (AWT) and Swing applications by registering a listener on a component. When you click the component (like a button), an event is fired and handled by the registered listener.
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 (IDE's).
The CDI event model allows beans to send events to one another without a compile-time dependency, and beans may create their own event payloads - a class that contains information pertinent to the event. Using CDI events, one bean can define the event, another can fire the event and a third can handle the event. And unlike with other event models, you can add listeners (observers) without registering them as listeners.
Duration: 45 minutes
CDI is one of several Java EE 6 features that help to integrate the web tier and the enterprise tier of the Java EE platform. CDI is a set of services that, used together, make it easy for developers to use enterprise beans along with JavaServer Faces technology in web applications. CDI also has many broader uses, allowing developers a great deal of flexibility to integrate various kinds of components in a loosely coupled but typesafe way.
A CDI stereotype allows you to create a annotation that club together several CDI annotations. For example, if we needed to create several CDI named beans with a scope of session, we would have to use two annotations in each of these beans, namely @Named and @SessionScoped. Instead of providing two annotations to each of the beans, you would create a stereotype, and then annotate the beans with it.
@Named
@SessionScoped
Stereotypes can be particularly useful in large applications where you have a number of beans that perform similar functions.
Duration: 30 minutes
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.
Release Date: 24-MAR-11
Release Date: 15-APR-11
Release Date: 15-FEB-10
Release Date: 20-JUN-12