2016-01-14 46 views
1

任何人都可以識別下面的命名空間聲明有什麼問題嗎?我已經提到了所有的命名空間,並提供了對模式文件的引用。不知道還有什麼缺失。匹配的通配符是嚴格的,但是對於元素'tx:annotation-driven''context:component-scan'沒有發現聲明

<?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:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="  
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd  
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd  
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 

    <context:component-scan base-package="com.mypackage" /> 
    <context:annotation-config /> 
    <tx:annotation-driven /> 

</beans> 

錯誤消息: - CVC-復type.2.4.c:

在此行中發現

多個註解的匹配通配符是嚴格的,但沒有聲明可以找到元素' TX:註解驅動的」。 - schema_reference.4:無法讀取模式文檔'http://www.springframework.org/schema/tx/spring-tx.xsd',因爲1) 找不到文檔; 2)文件無法閱讀; 3) 該文件的根元素不是<xsd:schema>

+2

聽起來像是日食問題 –

+0

如果您無法訪問上述[spring-tx.xsd](http://www.springframework.org/schema/tx/spring-tx.xsd),則會發生這種情況。通過在Web瀏覽器中進行測試來測試您的訪問權限。我可以訪問該XSD,並且您的XML確實可以爲我成功驗證。 – kjhughes

+0

如果不是這樣,請注意,[有些衝突版本的Spring jars導致類似於XSD訪問錯誤的錯誤](http://stackoverflow.com/a/29472455/290085)。 – kjhughes

回答

1

我更喜歡在STS Eclipse和這是一個如何重現該問題...

我有一個Spring上下文相關性的Maven項目:

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>betlista</groupId> 
    <artifactId>tests.so.q34779551</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>SO-q34779551</name> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>4.2.4.RELEASE</version> 
     </dependency> 
    </dependencies> 

</project> 

當我現在創建spring.xmlsrc/main/resources相同作爲你我有同樣的問題:

schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 
schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 
schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 
schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 

問題是,spring-txspring-context不在依賴關係中 - 添加時,錯誤是固定的。

更多詳細信息在this answer

+0

但我確實在我的項目依賴項中有tx和上下文jar。應用程序在部署到RAD上的Websphere時可以正常工作。它只是RAD(Eclipse)的抱怨.. – RKodakandla

+0

它可能是在Eclipse中的很多東西,代理例如...你也可以檢查[這個答案](http://stackoverflow.com/a/1075043/384674)對於本地模式版本... – Betlista

相關問題