GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing javaee.github.io — Injecting Beans

Java Platform, Enterprise Edition (Java EE) 8
The Java EE Tutorial

Previous Next Contents

Injecting Beans

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 Printer into 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.

Now that you can identify the target of the injection, it is important to understand what can be injected and in what context. JSF 2.3 provides producers that enable most important JSF artifacts to be injected. For detailed information, see the package javadoc for javax.faces.annotation.


Previous Next Contents
Oracle Logo  Copyright © 2017, Oracle and/or its affiliates. All rights reserved.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.