0

鉴于此文档中的此 XSD

<xs:element name="jdbc-user-service" substitutionGroup="security:any-user-service">
    <xs:annotation> .. etc </xs:annotation>
    <xs:complexType>
        <xs:attribute name="id" type="xs:token"></xs:attribute>
        <xs:attributeGroup ref="security:jdbc-user-service.attlist"/>
    </xs:complexType>
</xs:element>

<xs:attributeGroup name="jdbc-user-service.attlist">
    <xs:attribute name="data-source-ref" use="required" type="xs:token">
    </xs:attribute>
    <xs:attribute name="cache-ref" type="xs:token">
    </xs:attribute>
    <xs:attribute name="users-by-username-query" type="xs:token">
    </xs:attribute>
    <xs:attribute name="authorities-by-username-query" type="xs:token">
    </xs:attribute>
    <xs:attribute name="group-authorities-by-username-query" type="xs:token">     
    </xs:attribute>
    <xs:attribute name="role-prefix" type="xs:token">
    </xs:attribute>
</xs:attributeGroup>

那么为什么eclipse给我这个错误

cvc-complex-type.2.4.a:发现以元素“jdbc-user-service”开头的无效内容。'{"http://www.springframework.org/schema/security":user}' 之一是预期的。

当我提供以下 XML 时?

<jdbc-user-service
    data-source-ref="dataSource"
    users-by-username-query="SELECT u.uname, u.upwd, u.enabled FROM ucsdb.users u WHERE u.uname = ?"/>
4

1 回答 1

2

我认为你把事情搞混了。您可能从另一个XML 中得到这个错误。根据 XSD ,您发布的 XML(假设命名空间是正确的,请参见下文以防万一)是有效的。

<jdbc-user-service xmlns="http://www.springframework.org/schema/security" data-source-ref="dataSource" users-by-username-query="SELECT u.uname, u.upwd, u.enabled FROM ucsdb.users u WHERE u.uname = ?"/>

发布的 XSD 中唯一的“用户”元素来自此元素:

<xs:element name="user-service" substitutionGroup="security:any-user-service">
    <xs:annotation>
        <xs:documentation>Creates an in-memory UserDetailsService from a properties file or a list of "user" child elements. Usernames are converted to lower-case internally to allow for case-insensitive lookups, so this should not be used if case-sensitivity is required.</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" maxOccurs="unbounded" name="user">
                <xs:annotation>
                    <xs:documentation>Represents a user in the application.</xs:documentation>
                </xs:annotation>
                <xs:complexType>
                    <xs:attributeGroup ref="security:user.attlist"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="id" type="xs:token">
            <xs:annotation>
                <xs:documentation>A bean identifier, used for referring to the bean elsewhere in the context.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attributeGroup ref="security:properties-file"/>
    </xs:complexType>
</xs:element>

因此,您必须验证使用“用户服务”标签的 XML。

于 2012-10-18T03:12:54.877 回答