当前位置: 首页 > 知识库问答 >
问题:

错误消息“CVC-complex-type.4:属性'bean-discovery-mode'必须出现在元素'beans'上。”

商和颂
2023-03-14

这条信息是什么意思?我搜索了一下,但什么也没找到。什么可能导致这一切?

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

共有1个答案

翟俊哲
2023-03-14

消息明确表示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>
 类似资料: