2014-06-09 44 views
0

我遇到了spring jpa存儲庫的xml模式問題。spring數據 - jpa應用程序上下文模式錯誤

我嘗試了所有可用的在線建議,但似乎沒有解決它。

請大家幫忙。

在存儲庫的application-context.xml中出現此錯誤。

Multiple annotations found at this line: 
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'repository:repositories'. 
- 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"]}' is expected. 

我的應用程序上下文看起來像這樣

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:repository="http://www.springframework.org/schema/data/repository" 
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd 
     http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.7.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <jdbc:embedded-database id="dataSource" type="H2" /> 

    <tx:annotation-driven transaction-manager="transactionManager" /> 

    <repositories base-package="com.company.repositories" /> 

    <context:component-scan base-package="com.company.*" /> 
</beans> 

回答

0

大量的試驗後和錯誤以下應用程序上下文似乎沒有任何錯誤。

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" 
    xmlns:repository="http://www.springframework.org/schema/data/repository" 
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd 
     http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.7.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

    <jdbc:embedded-database id="dataSource" type="H2" /> 

    <tx:annotation-driven transaction-manager="transactionManager" /> 

    <jpa:repositories base-package="com.company.repositories" /> 

    <context:component-scan base-package="com.company.*" /> 
</beans> 

它超越了我爲什麼它沒有解決錯誤,當我早些時候嘗試它。

我收到以下錯誤。

Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-3.0.xsd). 

我做了以下操作,首選項>常規>網絡連接>緩存 - >刪除緩存xsd。

然後我點擊問題視圖並刪除問題並清理項目。現在不要有錯誤。任何理解這一點的人都歡迎回答。

1

我們通常建議引用在其中沒有版本號的模式文件,因爲這將確保在類路徑中選擇版本形式的依賴關係。

原因是XSD不知道任何種類的版本概念。這意味着spring-beans.xsdspring-beans-3.0.xsd與XSD完全無關,這意味着如果您碰巧導入了它們兩個(我會在第二秒鐘),這會產生錯誤,因爲XSD認爲它們中聲明的類型是宣佈兩次。

您可能會意外導入非版本化XSD的原因是Spring Data XSD實際上會引用它們來確保我們獲取最新版本(以便向前兼容)。

長話短說:從名稱中刪除顯式版本,你應該很好。

相關問題