我正在尝试使用:
<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; lineNumber:71; columnNumber: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}“是预期的。
我以为我正在装载所有东西......
<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">
答案 0 :(得分:6)
存储库标记的命名空间错误,只需将其更改为:
<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>
但是,最好只将存储库前缀重新分配给http://www.springframework.org/schema/data/jpa
命名空间,这是正常的convention