Java Reference
In-Depth Information
There is also a custom descriptor file available, which is used by WildFly to resolve de-
pendencies - jboss-deployment-structure.xml . It allows the developer to con-
figure the required dependencies in a fine-grained matter. The file is placed in the top-
level deployment file, in the META-INF directory (or WEB-INF for a web archive). A
sample content of the XML file (along with the XSD schema) is available at ht-
tps://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly .
So, if you have followed our checklist carefully, you will be aware that in order to let
Weld libraries kick in and automatically discover your CDI beans, you should add its core
configuration file, which is beans.xml . This file can be placed in your application at
the following locations:
• In your WEB-INF folder if you are developing a web application
• In your META-INF folder if you are deploying a JAR archive
The beans.xml file is based on the following schema reference:
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/
javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
However, it is perfectly legal to place an empty beans.xml file in the correct location;
if you do so, CDI will be enabled in your application. If you, however, do not place a
beans.xml file, then only an annotated subset of classes will be considered as beans. In
such a case, the container will create beans only for classes that are annotated with CDI-
related annotations and ignore the rest. Most of the times, this is not the behavior we ex-
pect, and it differs from the default mode in Java EE 6 (when the beans.xml file was
required).
You might have noticed that the bean-discovery-mode attribute is set to all in our
beans.xml file. This allows us to configure the CDI discovery mode we discussed in
the previous paragraph. It states that every legible class in our archive will be treated as a
managed bean. You can place a @Vetoed annotation on a class to filter it out from the
bean discovery process. It is also possible to set the discovery mode to annotated so
that you can place a scope annotation for every class that you would like to use as a bean.
Search WWH ::




Custom Search