2012-12-03 22 views
12

我在Eclipse中Maven的Spring項目,我在我的春天上下文的一有這個惱人的錯誤信息:錯誤在Spring應用程序上下文模式

引用的文件包含錯誤(JAR:文件:/ M2_HOME/repository/org/springframework/spring-beans/3.1.2.RELEASE/spring-beans-3.1.2.RELEASE.jar!/ org/springframework/beans/ factory/xml/spring-tool-3.1.xsd)。欲瞭解更多信息,請右鍵單擊在問題視圖的消息,並選擇「顯示詳細信息...」

展會setails導致了這一點:

enter image description here

我用彈簧DATA- jpa 1.2.0.RELEASE和我的其他彈簧罐都是3.1.3.RELEASE。關於spring-data-commons-core - 我甚至沒有依賴這個jar在我的pom中,但是我可以在m2版本庫中看到它,以及spring-data-commons-parent和版本1.4.0.RELEASE ,我不知道爲什麼(也許這些是spring-data-jpa的一部分?)。

我的應用程序上下文模式:

<?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:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" 
    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/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd 
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd"> 

我不明白爲什麼我不斷收到此錯誤。基本上,它沒有任何效果什麼那麼,該應用程序編譯,部署和運行良好,它只是在Eclipse這個惱人的紅色錯誤標記驅動我瘋了:)

回答

11

我已經做三件事情解決了這個問題:

  1. 加入這個倉庫到我的POM:

    <repository> 
        <id>spring-milestone</id> 
        <name>Spring Maven MILESTONE Repository</name> 
        <url>http://repo.springsource.org/libs-milestone</url> 
    </repository> 
    
  2. 我使用這個版本的春天JPA的:

    <dependency> 
        <groupId>org.springframework.data</groupId> 
        <artifactId>spring-data-jpa</artifactId> 
        <version>1.2.0.RELEASE</version> 
    </dependency> 
    
  3. 我刪除了XSD版本從我的背景下(雖然我不知道它是必要的):

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

我希望這有助於。

+0

老兄的作品就像一個魅力,也爲mongodb! (有幾個技巧)。我將其添加爲單獨的答案,謝謝! – tugcem

+0

很高興聽到這個:) – forhas

3

最近我有同樣的問題與JPA-1.3

沒有工作,直到我用明確的tools.xsd鏈接

xsi:schemaLocation=" ... 
    http://www.springframework.org/schema/tool 
    http://www.springframework.org/schema/tool/spring-tool-3.2.xsd 
    ... "> 

這樣的:

<?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:p="http://www.springframework.org/schema/p" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
    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.2.xsd 
     http://www.springframework.org/schema/tx 
     http://www.springframework.org/schema/tx/spring-tx-3.2.xsd 
     http://www.springframework.org/schema/jdbc 
     http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.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/tool 
     http://www.springframework.org/schema/tool/spring-tool-3.2.xsd 
     "> 
+0

與上下文相同的問題4.2。並解決它。有趣的是http://www.springframework.org/schema/context/spring-context-4.2.xsd鏈接到4.1彈簧工具 – borjab

6

我做什麼用的彈簧-data-jpa-1.3正在向xsd添加一個版本並將其降低到1.2。然後錯誤消息消失。像這樣

<beans 
     xmlns="http://www.springframework.org/schema/beans" 
     ... 
     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.xsd 
    ... 
    http://www.springframework.org/schema/data/jpa 
    http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd"> 

似乎它被固定爲1.2,但隨後又出現在1.3中。

+0

+1使用舊的模式也爲我工作。 – elias

3

什麼@forhas和@HRgiger也爲我工作。我正在使用spring-data-mongodb而不是jpa

但是,對於mongodb綁定,您不應刪除mongodb引用xsd的版本,只需將其與版本保持一致即可:http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd。應該刪除contextbeans版本。

16

我最近在最新的Eclipse(Kepler)中遇到了類似的問題,並通過在首選項> XML> XML文件>驗證中禁用「尊重所有XML架構位置」選項來修復它。 它禁用了對指向不同模式位置的相同名稱空間的引用的驗證,只取得了通常在驗證的XML文件中找到的第一個名稱空間。該選項來自Xerces庫。

WTP文件:http://www.eclipse.org/webtools/releases/3.1.0/newandnoteworthy/sourceediting.php

Xerces的文件:http://xerces.apache.org/xerces2-j/features.html#honour-all-schemaLocations

+0

也在Eclipse中爲我工作。7 – Brian

+0

適用於Eclipse Mars的Spring雜湊項目 –

4

最近我和春天4.0同樣的問題。

這是由spring-beans-4.0.xsdspring-context-4.0.xsd的名稱衝突造成的。 開幕spring-context-4.0.xsd你可以看到,spring-beans-4.0.xsd是進口同類如下:

<xsd:import namespace="http://www.springframework.org/schema/beans" 
schemaLocation="http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"/> 

這些名稱的衝突使Eclipse抱怨「......一個模式不能包含具有相同名稱的兩個全球性成分......」

一個值得注意的方面是,我沒有Eclipse Kepler SR2的這個問題,但Eclipse Luna SR1比較了兩種有關XML驗證的偏好,它們是相同的。

它是解決從XSI去除彈簧上下文4.0.xsd:schemaLocation屬性:

http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.0.xsd 

在這之後一切工作就像預期。

+1

但是,如果您使用的是 但它不會解決問題我還沒弄明白問題。 –

2

有時spring config xml文件在下次eclipse打開時效果不好。

無論是重新打開eclipse還是清理項目都不起作用,它都會在模式定義所導致的xml文件中顯示錯誤。

但試試這個!

右鍵單擊spring config xml文件,然後選擇validate

過了一會兒,錯誤消失,eclipse告訴你這個文件沒有錯誤。

這是什麼玩笑...

+0

這是爲我做的,謝謝。 – Bevor

相關問題