Java Reference
In-Depth Information
13.5.3. Using the bean-discovery-mode annotation
Once the beans.xml file could remain empty, and it served only as a marker for CDI; re-
quests have been made to remove it altogether. The Java EE 7 specification has done just
that. The bean-discovery-mode annotation has defined three modes that CDI uses to
scan your classes in Java EE 7 applications. Table 13.3 describes these modes.
Table 13.3. Values for the bean-discovery-mode annotation
Value
Description
All types are processed. This behavior is the same as in-
cluding the beans.xml in a Java EE 6 application.
ALL
Only types with bean-defining annotations are processed.
This is the default Java EE 7 behavior.
ANNOTATED
NONE
All types in the archive (JAR) will be ignored.
In a Java EE 7 application, there's no need to include a beans.xml file. With no beans.xml
file, CDI 1.1 will default to a beans discovery mode of ANNOTATED as described in table
13.3 . This default behavior can be overridden by including a beans.xml and specifying a
value for bean-discovery-mode , as shown in the following listing.
Listing 13.15. Specifying a value for bean-discovery-mode
In this listing the value of bean-discovery-mode is set to "all" , overriding the
default Java EE 7 behavior and allowing all types to be processed as in Java EE 6.
Packaging your CDI code inside of JAR archives or EE modules is pretty easy. Next we'll
go over some best practices for packaging and common problems you may run into.
 
Search WWH ::




Custom Search