Reputation: 7653
I have a simple Java EE project and under WEB-INF there is a simple beans.xml. It basically contains nothing. But I always got this error message "cvc-complex-type.4: Attribute 'bean-discovery-mode' must appear on element 'beans'." indicated for the line "http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" in JBoss Developer Studio.
What does this message mean? I googled but found nothing. What might cause this?
<?xml version="1.0" encoding="UTF-8"?>
<!-- Marker file indicating CDI should be enabled -->
<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">
<!-- Uncomment this alternative to see EJB declarative transactions in
use -->
<!-- <alternatives> -->
<!-- <class>org.jboss.as.quickstarts.greeter.domain.EJBUserDao</class> -->
<!-- </alternatives> -->
</beans>
Upvotes: 3
Views: 6851
Reputation: 16441
The message clearly says the attribute bean-discovery-mode
should be there in element beans
, this may be a requirement of your container. Try giving the attribute to bean element as follows:
bean-discovery-mode = "annotated"
The reason is you are using CDI 1.1, and therefore bean-discovery-mode
is a compulsory attribute. You may confirm it by reading the XSD file available from the following URL:
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd
.
Note the following portion in particular:
<xs:attribute name="bean-discovery-mode" use="required">
<xs:annotation>
<xs:documentation>
It is strongly recommended you use "annotated".
If the bean discovery mode is "all", then all types in this
archive will be considered. If the bean discovery mode is
"annotated", then only those types with bean defining annotations will be
considered. If the bean discovery mode is "none", then no
types will be considered.
</xs:documentation>
</xs:annotation>
Upvotes: 3