Java Reference
In-Depth Information
Here, the injected EJB proxy just points to a pool of stateless instances (or a single
bean instance for stateful beans). There is no automatic association between the
HTTP request or HTTP session and a given EJB instance.
The opposite is true for CDI Beans, which live in well-defined scopes. For example,
the following CDI Bean lives in a RequestScoped , that is, it will be destroyed at the
end of the request:
@RequestScoped
@Named
public class Customer {
private String name;
private String surname;
public String getName(){
return name;
}
public String getSurname(){
return surname;
}
}
The above CDI Bean can be safely injected into our former servlet and, at the end
of an HTTP session or HTTP request, all instances associated with this scope are
automatically destroyed and, thus, garbage collected.
public class HelloServlet extends HttpServlet {
@InjectCustomerServiceservice;
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
. . . .
Search WWH ::




Custom Search