2012-05-15 22 views
1

我試圖使用方法:調度員的servlet:無效的含量被發現開始元素「資源庫」

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

,但我不斷收到此錯誤:

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.

我以爲我是裝一切正常......

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

回答

6

的倉庫標籤的命名空間是錯誤的,只是將其更改爲:

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

或XML的默認命名空間設置爲倉庫:

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> 

但它可能會更好,只是重新分配資源庫公關EFIX到http://www.springframework.org/schema/data/jpa命名空間,而不是,這是正常的convention

+0

這似乎是工作...之類的...'匹配通配符是嚴格的,但沒有聲明可以爲元素「庫中找到:repositories'' – Webnet

+0

不該我只需要能夠放入'@ Repository'? – Webnet

+0

是@Webnet,我已經更新了答案,我的名字空間錯了。你仍然需要把這個告訴哪個軟件包要掃描Repository組件,儘管 –

相關問題