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

Dispatcher-Servlet:发现以元素“repositories”开头的内容无效

和嘉澍
2023-03-14
<repositories base-package="com.site.cmt.repositories" repository-impl-postfix="">
    <repository id="variableRepository" />
</repositories>

org.springframework.beans.factory.XML.xmlBeanDefinitionStoreException:ServletContext资源[/web-inf/dispatcher-servlet.XML]的XML文档中的第71行无效;嵌套异常是org.xml.sax.SAXParseException;行号:71;列号:94;CVC-complex-type2.4.a:发现以元素“repositories”开头的内容无效。应为“{”http://www.springframework.org/schema/beans“:导入、”http://www.springframework.org/schema/beans“:别名、”http://www.springframework.org/schema/beans“:bean、WC[##其他:”http://www.springframework.org/schema/beans“]、”http://www.springframework.org/schema/beans“:beans}”之一。

我以为我把所有东西都装对了...

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.1.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
       http://www.springframework.org/schema/jee 
       http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
       http://www.springframework.org/schema/data/jpa
       http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd">

共有1个答案

麹承
2023-03-14

repositories标记的名称空间是错误的,只需将其更改为:

<repository:repositories base-package="com.site.cmt.repositories" repository-impl-postfix="">
    <repository:repository id="variableRepository" />
</repository:repositories>

或者将xml的默认名称空间设置为Repository:

xmlns="http://www.springframework.org/schema/data/repository"

更新:很抱歉,我弄错了名称空间,在您的示例中,实际上您使用了jpa作为与存储库相关的正确名称空间的前缀,该名称空间是http://www.springframework.org/schema/data/jpa,因此您基本上必须使用:

<jpa:repositories base-package="com.site.cmt.repositories" repository-impl-postfix="">
    <jpa:repository id="variableRepository" />
</jpa:repositories>
 类似资料: