type=page
status=published
title=Beans as Injectable Objects
next=cdi-basic006.html
prev=cdi-basic004.html
~~~~~~
= Beans as Injectable Objects


[[GIZKS]]

[[beans-as-injectable-objects]]
Beans as Injectable Objects
---------------------------

The concept of injection has been part of Java technology for some time.
Since the Java EE 5 platform was introduced, annotations have made it
possible to inject resources and some other kinds of objects into
container-managed objects. CDI makes it possible to inject more kinds of
objects and to inject them into objects that are not container-managed.

The following kinds of objects can be injected:

* Almost any Java class
* Session beans
* Java EE resources: data sources, Java Message Service topics, queues,
connection factories, and the like
* Persistence contexts (Java Persistence API `EntityManager` objects)
* Producer fields
* Objects returned by producer methods
* Web service references
* Remote enterprise bean references

For example, suppose that you create a simple Java class with a method
that returns a string:

[source,oac_no_warn]
----
package greetings;

public class Greeting {
    public String greet(String name) {
        return "Hello, " + name + ".";
    }
}
----

This class becomes a bean that you can then inject into another class.
This bean is not exposed to the EL in this form.
link:cdi-basic009.html#GJBAK[Giving Beans EL Names] explains how you can
make a bean accessible to the EL.
