December 2017
Intermediate to advanced
372 pages
8h 46m
English
Another new feature introduced in CDI 2.0 is the ability to specify in which order our observer methods handle CDI events. This can be accomplished via the @Priority annotation, as illustrated in the following example:
import javax.annotation.Priority;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Observes;
import javax.interceptor.Interceptor;
@SessionScoped
public class EventHandler{
void handleIt ( @Observes @Priority(Interceptor.Priority.APPLICATION) MyEvent me){
//handle the event
}
}
The @Priority annotation takes an argument of type int. This argument specifies the priority for the observer method. The highest priority is defined by the APPLICATION constant defined in the Interceptor.Priority ...