Java Spring 3.0 - 无法为 XML 架构命名空间找到 Spring NamespaceHandler [http://www.springframework.org/schema/security]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2161050/
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
Spring 3.0 - Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
提问by Taylor Leese
Any ideas what could be the cause of this?
任何想法可能是什么原因?
Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
无法为 XML 架构命名空间找到 Spring NamespaceHandler [ http://www.springframework.org/schema/security]
org.springframework.web.context.ContextLoader initWebApplicationContext: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]
This is my applicationContext.xml:
这是我的 applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
...
</beans:beans>
In my pom.xml I have:
在我的 pom.xml 我有:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-openid</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
采纳答案by Taylor Leese
I needed to add an additional Maven dependency:
我需要添加一个额外的 Maven 依赖项:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
回答by James Jithin
I had the same error message while trying to deploy the application. In Spring, the security configuration xml can be a different one from applicationContext.xml, usually applicationContext-security.xml inside WEB-INF folder. The changes to be applied are for web.xml
我在尝试部署应用程序时遇到了相同的错误消息。在 Spring 中,安全配置 xml 可以与 applicationContext.xml 不同,通常是 WEB-INF 文件夹中的 applicationContext-security.xml。要应用的更改适用于 web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
And the applicationContext.xml would look like:
applicationContext.xml 看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http auto-config='true'>
<intercept-url pattern="/login.jsp" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/**" access="ROLE_USER" />
<form-login login-page='login.jsp'/>
</http>
</beans:beans>
Even after you make these changes, the namespace error will exist. To get rid of this, add the following jar files to the WEB-INF/lib and then to the library:
即使进行了这些更改,命名空间错误仍将存在。要摆脱这种情况,请将以下 jar 文件添加到 WEB-INF/lib,然后添加到库中:
- spring-security-acl-3.1.0.M2.jar
- spring-security-config-3.1.0.M2.jar
- spring-security-core-3.1.0.M2.jar
- spring-security-taglibs-3.1.0.M2.jar
- spring-security-web-3.1.0.M2.jar
- spring-security-acl-3.1.0.M2.jar
- spring-security-config-3.1.0.M2.jar
- spring-security-core-3.1.0.M2.jar
- spring-security-taglibs-3.1.0.M2.jar
- spring-security-web-3.1.0.M2.jar
回答by Peter Sankauskas
The solution is definitely "spring-security-config" not in your WEB-INF/lib.
解决方案绝对是“spring-security-config”,不在您的 WEB-INF/lib 中。
For my project in Eclipse using Maven, it turned out not all of the maven dependencies were being copied to WEB-INF/lib. Looking at Project -> Properties -> Deployment Assembly, only some of the jars were being copied.
对于我在 Eclipse 中使用 Maven 的项目,结果不是所有的 Maven 依赖项都被复制到 WEB-INF/lib。查看 Project -> Properties -> Deployment Assembly,只有一些 jars 被复制。
To fix this, I clicked "Add", then "Java Build Path Entires" and finally "Maven Dependencies".
为了解决这个问题,我点击了“添加”,然后点击了“Java Build Path Entires”,最后点击了“Maven Dependencies”。
I have been searching SO and the web for the last hour looking for this, so hopefully this helps someone else.
在过去的一个小时里,我一直在搜索 SO 和网络来寻找这个,所以希望这可以帮助其他人。
回答by arviarya
If you already have all dependencies in your pom, try:
1. Remove all downloaded jars form your maven repository folder for 'org->springframework'
2. Make a maven clean build.
如果您的 pom 中已经拥有所有依赖项,请尝试:
1. 从 'org->springframework' 的 Maven 存储库文件夹中删除所有下载的 jar
2. 进行 Maven 清洁构建。
回答by shapiy
I have encountered the very similar problem today. For some reason IntelliJ IDEA
haven't included Spring Security jar files while deploying the application. I think I should agree with the majority of posters here.
我今天遇到了非常相似的问题。由于某种原因,IntelliJ IDEA
在部署应用程序时没有包含 Spring Security jar 文件。我想我应该同意这里的大多数海报。
回答by abhiram
I used spring-security-config jar it resolved the problem for me
我使用了 spring-security-config jar 它为我解决了问题
回答by George Papatheodorou
A nice list of Maven Dependencies exists at : Spring SiteThe major artifacts needed are:
一个不错的 Maven 依赖项列表位于:Spring Site所需的主要工件是:
- spring-security-core
- Spring-security-web
- spring-security-config
- 弹簧安全核心
- Spring-security-web
- 弹簧安全配置
回答by ForestierSimon
@James Jithin - such exception can appear also when you have two different versions of beans and security schema in xsi:schemaLocation. It's the case in the snippet you have pasted:
@James Jithin - 当您在 xsi:schemaLocation 中有两个不同版本的 bean 和安全模式时,也会出现此类异常。您粘贴的代码段就是这种情况:
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd"
In my case changing them both to 3.1 solved the problem
在我的情况下,将它们都更改为 3.1 解决了问题
回答by user64141
I got this error while deploying to Virgo. The solution was to add this to my bundle imports:
部署到 Virgo 时出现此错误。解决方案是将其添加到我的包导入中:
org.springframework.transaction.config;version="[3.1,3.2)",
I noticed in the Spring jars under META-INF there is a spring.schemas and a spring.handlers section, and the class that they point to (in this case org.springframework.transaction.config.TxNamespaceHandler) must be imported.
我注意到在 META-INF 下的 Spring jar 中有一个 spring.schemas 和一个 spring.handlers 部分,并且必须导入它们指向的类(在这种情况下为 org.springframework.transaction.config.TxNamespaceHandler)。
回答by Patrick Herrera
I struggled with this for a while and none of these answers helped. Thanks to the comment from user64141I realised that there was a problem with the spring.handlers
files.
我为此挣扎了一段时间,但这些答案都没有帮助。感谢user64141的评论,我意识到spring.handlers
文件有问题。
I am using the Shade plugin for Maven to generate a fat jar, and all the spring.handlers
(and spring.schemas
) files were being overwritten by each Spring dependency.
我正在使用 Maven 的 Shade 插件生成一个胖 jar,并且所有spring.handlers
(和spring.schemas
)文件都被每个 Spring 依赖项覆盖。
The Maven site covers this exact problem and how to solve it by appending the files together instead:
Maven 站点涵盖了这个确切的问题以及如何通过将文件附加在一起来解决它: