dispatcher-servlet:发现以元素“存储库"开头的无效内容 [英] dispatcher-servlet: Invalid content was found starting with element 'repositories'
问题描述
我正在尝试使用:
<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-type.2.4.a:发现以元素repositories"开头的无效内容.'{"http://www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, "http://www.springframework.org" 之一/schema/beans":bean, WC[##other:"http://www.springframework.org/schema/beans"], "http://www.springframework.org/schema/beans":beans}'预计.
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 71 in XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 71; columnNumber: 94; cvc-complex-type.2.4.a: Invalid content was found starting with element 'repositories'. One of '{"http://www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, "http://www.springframework.org/schema/beans":bean, WC[##other:"http://www.springframework.org/schema/beans"], "http://www.springframework.org/schema/beans":beans}' is expected.
我以为我正确加载了所有内容...
I thought I was loading everything correctly...
<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">
推荐答案
repositories标签的命名空间有误,改成:
The namespace for the repositories tag is wrong, just change it to:
<repository:repositories base-package="com.site.cmt.repositories" repository-impl-postfix="">
<repository:repository id="variableRepository" />
</repository:repositories>
或者将xml的默认命名空间设置为repository:
or set the default namespace of the xml to repository:
xmlns="http://www.springframework.org/schema/data/repository"
更新:抱歉,我弄错了命名空间,在您的情况下,实际上您使用 jpa
作为与存储库相关的正确命名空间的前缀 http://www.springframework.org/schema/data/jpa
,所以你基本上必须使用:
Update:
I am sorry, I got the namespace wrong, in your case actually you have used jpa
as the prefix for the correct repository related namespace which is http://www.springframework.org/schema/data/jpa
, so you essentially have to use:
<jpa:repositories base-package="com.site.cmt.repositories" repository-impl-postfix="">
<jpa:repository id="variableRepository" />
</jpa:repositories>
但最好将存储库前缀重新分配给 http://www.springframework.org/schema/data/jpa
命名空间,这是正常的 约定
But it might be better to just re-assign the repository prefix to the http://www.springframework.org/schema/data/jpa
namespace instead, that is the normal convention
这篇关于dispatcher-servlet:发现以元素“存储库"开头的无效内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!