Java Reference
In-Depth Information
}
}
Latest improvements in action
Having been introduced to the platform from Java EE 6, CDI has become an import-
ant solution for component oriented programming in the Java EE platform. Now it
only has to spread its tentacles into almost all specifications of the platform so that
it can link seamlessly more components and integrate more APIs. In the long list of
improvements that have been made, we will present a few including: the possibility
of avoiding a bean being processed by the CDI, access to the current CDI container,
access to the non contexual instances of a bean, and finally the ability to explicitly
destroy bean instances. The improvement of CDI relating to interceptors and decor-
ators will be presented in the next chapter when we will discuss the relevant specific-
ation.
Avoiding CDI processing on a bean
Version 1.1 of the CDI Specification came with the annotation @vetoed that pre-
vents an object being considered as a CDI bean. However, a bean decorated with
this annotation cannot have a lifecycle similar to the contextual instance. So, it can-
not be injected.
By looking at this annotation, some might wonder about its usefulness. To preserve
the integrity of some data, it may happen that you need to control the use of some
components. But, by using CDI, your components can be manipulated from any oth-
er component. Hence the role of the @vetoed annotation. The following code shows
us the use of the @vetoed annotation on the Student entity in order to avoid un-
known manipulations that can lead to inconsistencies:
@Entity
@Vetoed
public class Student implements Serializable {
@Id
private String id;
private String firstname;
Search WWH ::




Custom Search