spring 应用程序上下文模式中的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13693065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error in spring application context schema
提问by forhas
I have a maven-spring project in Eclipse and I have this annoying error message in one of my spring contexts:
我在 Eclipse 中有一个 maven-spring 项目,并且在我的一个 spring 上下文中出现了这条烦人的错误消息:
Referenced file contains errors (jar:file:/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). For more information, right click on the message in the Problems View and select "Show Details..."
引用的文件包含错误 (jar:file:/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)。有关更多信息,请右键单击问题视图中的消息并选择“显示详细信息...”
The show setails leads to this:
节目的尾巴导致了这个:


I using spring-data-jpa 1.2.0.RELEASE and the rest of my spring jars are 3.1.3.RELEASE. Regarding spring-data-commons-core - I don't even have a dependency to this jar in my pom but I can see it in my m2 repository along with spring-data-commons-parent and both of version 1.4.0.RELEASE, I don't know why (maybe those are part of spring-data-jpa?).
我使用 spring-data-jpa 1.2.0.RELEASE,其余的 spring jar 是 3.1.3.RELEASE。关于 spring-data-commons-core - 我什至在我的 pom 中都没有对这个 jar 的依赖,但我可以在我的 m2 存储库中看到它以及 spring-data-commons-parent 和两个版本 1.4.0.RELEASE ,我不知道为什么(也许那些是 spring-data-jpa 的一部分?)。
My application context schema:
我的应用程序上下文架构:
<?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">
I don't understand why I keep getting this error. Basically it has no effect what so ever, The app compiles, deployed and runs just fine, it is just this annoying red error mark in Eclipse that drives me crazy :)
我不明白为什么我不断收到此错误。基本上它没有任何影响,应用程序编译、部署和运行都很好,只是 Eclipse 中这个烦人的红色错误标记让我发疯:)
采纳答案by forhas
I have solved it by doing 3 things:
我通过做三件事解决了它:
Added this repository to my POM:
<repository> <id>spring-milestone</id> <name>Spring Maven MILESTONE Repository</name> <url>http://repo.springsource.org/libs-milestone</url> </repository>I'm using this version of spring-jpa:
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.2.0.RELEASE</version> </dependency>I removed the xsd versions from my context (although I'm not sure it is necessary):
<?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">
将此存储库添加到我的 POM:
<repository> <id>spring-milestone</id> <name>Spring Maven MILESTONE Repository</name> <url>http://repo.springsource.org/libs-milestone</url> </repository>我正在使用这个版本的 spring-jpa:
<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.2.0.RELEASE</version> </dependency>我从上下文中删除了 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">
I hope this helps.
我希望这有帮助。
回答by Ulises
I recently had a similar problem in latest Eclipse (Kepler) and fixed it by disabling the option "Honour all XML schema locations" in Preferences > XML > XML Files > Validation. It disables validation for references to the same namespaces that point to different schema locations, only taking the first found generally in the XML file being validated. This option comes from the Xerces library.
我最近在最新的 Eclipse (Kepler) 中遇到了类似的问题,并通过在首选项 > XML > XML 文件 > 验证中禁用“尊重所有 XML 模式位置”选项来修复它。它禁用对指向不同模式位置的相同命名空间的引用的验证,只采用通常在被验证的 XML 文件中找到的第一个。此选项来自 Xerces 库。
WTP Doc: http://www.eclipse.org/webtools/releases/3.1.0/newandnoteworthy/sourceediting.php
WTP 文档:http: //www.eclipse.org/webtools/releases/3.1.0/newandnoteworthy/sourceediting.php
Xerces Doc: http://xerces.apache.org/xerces2-j/features.html#honour-all-schemaLocations
Xerces 文档:http: //xerces.apache.org/xerces2-j/features.html#honour-all-schemaLocations
回答by user1278890
What I did with spring-data-jpa-1.3 was adding a version to xsd and lowered it to 1.2. Then the error message disappears. Like this
我对 spring-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">
Seems like it was fixed for for 1.2 but then appears again in 1.3.
似乎它是为 1.2 修复的,但随后又出现在 1.3 中。
回答by Ajax
Sometimes the spring config xml file works not well on next eclipse open up.
有时,spring 配置 xml 文件在下一次 eclipse 打开时效果不佳。
It shows error in the xml file caused by schema definition, no matter reopen eclipse or clean up project are both not working.
它显示由模式定义引起的xml文件错误,无论是重新打开eclipse还是清理项目都不起作用。
But try this!
但是试试这个!
Right click on the spring config xml file, and select
validate.
右键单击 spring 配置 xml 文件,然后选择
validate.
After a while, the error disappears and eclipse tells you there is no error on this file.
过了一会儿,错误消失了,eclipse 告诉你这个文件没有错误。
What a joke...
真是笑话...
回答by ame-h
I recently had same issue with Spring 4.0.
我最近在 Spring 4.0 上遇到了同样的问题。
It was caused by a collision in names from spring-beans-4.0.xsdand spring-context-4.0.xsd.
Opening spring-context-4.0.xsdyou can see that spring-beans-4.0.xsdis imported like follow:
这是由spring-beans-4.0.xsd和 的名称冲突引起的spring-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"/>
These name's collisions make Eclipse complain about "...A schema cannot contain two global components with the same name..."
这些名称的冲突使 Eclipse 抱怨“...架构不能包含两个具有相同名称的全局组件...”
A noteworthy aspect is that I hadn't this problem with Eclipse Kepler SR2 but Eclipse Luna SR1, comparing both preferences about XML Validation, they were the same.
一个值得注意的方面是我在 Eclipse Kepler SR2 上没有这个问题,但在 Eclipse Luna SR1 上没有这个问题,比较两个关于 XML 验证的偏好,它们是相同的。
It was solved by removing spring-context-4.0.xsd from xsi:schemaLocation attribute:
它是通过从 xsi:schemaLocation 属性中删除 spring-context-4.0.xsd 来解决的:
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
After this everything worked as expected.
在此之后,一切都按预期进行。
回答by snowindy
I have recently had same issue with JPA-1.3
我最近在 JPA-1.3 上遇到了同样的问题
Nothing worked until I used explicit tools.xsd link
在我使用明确的 tools.xsd 链接之前,什么都不起作用
xsi:schemaLocation=" ...
http://www.springframework.org/schema/tool
http://www.springframework.org/schema/tool/spring-tool-3.2.xsd
... ">
like this:
像这样:
<?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
">
回答by tugcem
What @forhas and @HRgiger did also worked for me. I am using spring-data-mongodbinstead of jpa.
@forhas 和 @HRgiger 所做的也对我有用。我正在使用spring-data-mongodb而不是jpa.
However, for mongodb bindings, you should not remove the version of mongodb reference xsd, just keep it with version: http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd. contextand beansversions should be removed.
但是,对于 mongodb 绑定,您不应删除 mongodb 引用 xsd 的版本,只需将其保留为 version: http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd。context和beans版本应该被删除。
回答by Tushar Kshirsagar
If you don't have control those files, as those files can be part of other projects and you are not authorized to make any changes, then you can bypass those errors in eclipse by going, Preferences --> XML --> XML Files --> Validation --> Referenced file contains errors --> choose Ignore option.
如果您无法控制这些文件,因为这些文件可以是其他项目的一部分,并且您无权进行任何更改,那么您可以通过 Preferences --> XML --> XML Files 在 Eclipse 中绕过这些错误--> 验证 --> 引用的文件包含错误 --> 选择忽略选项。
And let project get's validated, the error message will disappear.
并让项目得到验证,错误信息就会消失。
回答by Sameer Sinha
I removed this error by updating the version number in
我通过更新版本号消除了这个错误
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
to 4.3 as I had upadated spring version in pom as 4.3.7.RELEASE
到 4.3,因为我已经将 pom 中的 spring 版本更新为 4.3.7.RELEASE
回答by Ankit Gujrathi
Referenced file contains errors (http://www.springframework.org/schema/context/spring-context-3.0.xsd)
引用的文件包含错误(http://www.springframework.org/schema/context/spring-context-3.0.xsd)
i faced this problem, when i was configuring dispatcher-servlet.xml ,you can remove this:
我遇到了这个问题,当我配置 dispatcher-servlet.xml 时,你可以删除它:
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
from your xml and you can also follow the steps go to window -> preferences -> validation -> and unchecked XML validator and XML schema validator.
从您的 xml 中,您也可以按照以下步骤转到窗口 -> 首选项 -> 验证 -> 和未选中的 XML 验证器和 XML 架构验证器。

