错误消息"cvc-complex-type.4: Attribute 'bean-discovery-mode' must appear on element 'beans'."



我有一个简单的Java EE项目,在WEB-INF下有一个很简单的beans.xml。它基本上什么都不包含。但我总是收到这样的错误消息"cvc复杂类型.4:元素'beans'上必须出现属性'beansdiscoverymode'。"http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"在JBoss Developer Studio中。

这个信息是什么意思?我在谷歌上搜索了一下,但一无所获。是什么原因造成的?

<?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>

消息明确表示属性bean-discovery-mode应该在元素beans中,这可能是容器的要求。尝试将属性赋予bean元素,如下所示:

bean-discovery-mode = "annotated"

原因是您使用的是CDI1.1,因此bean-discovery-mode是一个强制属性。您可以通过从以下URL读取可用的XSD文件来确认:

http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd

特别注意以下部分:

<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>

相关内容

最新更新