Injecting Beans - The Java EE 6 Tutorial (original) (raw)
In order to use the beans you create, you inject them into yet another bean that can then be used by an application, such as a JavaServer Faces application. For example, you might create a bean called Printerinto which you would inject one of the Greeting beans:
import javax.inject.Inject;
public class Printer {
@Inject Greeting greeting;
...
This code injects the @Default Greeting implementation into the bean. The following code injects the @Informal implementation:
import javax.inject.Inject;
public class Printer {
@Inject @Informal Greeting greeting;
...
More is needed for the complete picture of this bean. Its use of scope needs to be understood. In addition, for a JavaServer Faces application, the bean needs to be accessible through the EL.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices