Comparing JSF Beans, CDI Beans and EJBs | Andy Gibson - 0 views
-
differences between CDI beans and EJBs is that EJBs are : Transactional Remote or local Able to passivate stateful beans freeing up resources Able to make use of timers Can be asynchronous
-
Stateless EJBs can be thought of as thread safe single-use beans that don’t maintain any state between two web requests
-
Stateful EJBs do hold state and can be created and sit around for as long as they are needed until they are disposed of
- ...15 more annotations...
-
Stateless beans must have a dependent scope while a stateful session bean can have any scope. By default they are transactional, but you can use the transaction attribute annotation.
-
In general, you should use CDI beans unless you need the advanced functionality available in the EJBs such as transactional functions. You can write your own interceptor to make CDI beans transactional, but for now, its simpler to use an EJB until CDI gets transactional CDI beans which is just around the corner
-
In short, don’t use them if you are developing for Java EE 6 and using CDI. They provide a simple mechanism for dependency injection and defining backing beans for web pages, but they are far less powerful than CDI beans.
-
interceptors, conversation scope, Events, type safe injection, decorators, stereotypes and producer methods
-
JSF-like features, you can define the scope of the CDI bean using one of the scopes defined in the javax.enterprise.context package (namely, request, conversation, session and application scopes). If you want to use the CDI bean from a JSF page, you can give it a name using the javax.inject.Named annotation