Java Reference
In-Depth Information
To make use of the alternative implementation, the alternative class must be specified within the beans.xml,
which can be changed at deployment time.
<beans ... >
In order to use the standard implementation rather than the alternative, simply comment out the
<alternatives> elements along with all enclosing alternative class specifications.
In CDI 1.1, the @Priority annotation can be used to indicate that an alternative is to be used for an entire
application. For instance, in the following code, the EmployeeProcessorTestImpl alternative contains a priority of
public class EmployeeProcessorTestImpl implements Hire {
For more information on alternatives, please see the online documentation in the Java EE 7 tutorial.
The @New annotation was previously used to allow the application to obtain a new instance of a bean, which is not
bound to the declared scope but has had dependency injection performed. The CDI 1.1 update deprecates the use
of the @New qualifier and injects @Dependent -scoped beans instead. Let's take a look at how the @New qualifier used to
work, and then you will learn how to utilize the @Dependent scope instead.
In the following example, the @New qualifier is specified at an injection point to obtain a new instance of a bean
that is not bound to the declared scope.
@Produces @ConversationScoped
Order getOrder(@New(Order.class) Order order){
This same type of result can be achieved by declaring a bean as @Dependent . When a bean is declared to have
@Dependent scope, the following are all true:
It is not possible to share an injected instance of that bean between any other injection points.
Any instance of the bean that has been injected into an object that is created by the container
is bound to the same life cycle as the newly created object.
At most one instance of the bean is instantiated if referred to within JSF or JSP EL.
Search WWH ::

Custom Search