无法为 XML 架构命名空间找到 Spring NamespaceHandler [http://www.springframework.org/schema/security]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7188719/
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
Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
提问by Amit
I am developing my first application in spring security. My applicationContext-security.xml file looks like this:
我正在开发我的第一个 Spring Security 应用程序。我的 applicationContext-security.xml 文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Namespace-based OpenID configuration
-->
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="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.0.xsd">
<http>
<intercept-url pattern="/**" access="ROLE_USER"/>
<intercept-url pattern="/index.xhtml*" filters="none"/>
<logout/>
<openid-login login-page="/index.xhtml" authentication-failure-url="/index.xhtml?login_error=true">
<attribute-exchange>
<openid-attribute name="email" type="http://schema.openid.net/contact/email" required="true" count="2"/>
<openid-attribute name="name" type="http://schema.openid.net/namePerson/friendly" />
</attribute-exchange>
</openid-login>
<remember-me token-repository-ref="tokenRepo"/>
</http>
<b:bean id="tokenRepo"
class="org.springframework.security.web.authentication.rememberme.InMemoryTokenRepositoryImpl" />
<authentication-manager alias="authenticationManager"/>
<user-service id="userService">
<user name="http://user.myopenid.com/" authorities="ROLE_SUPERVISOR,ROLE_USER" />
</user-service>
</b:beans>
and Web.xml file is:
和 Web.xml 文件是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>Spring Security OpenID Demo Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>openid.root</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Clean and Build of the application is successful, but when I try to deploy the application jetty 7 gives me following error:
应用程序的清理和构建成功,但是当我尝试部署应用程序时,jetty 7 出现以下错误:
SEVERE: 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-security.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
严重:上下文初始化失败
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法为 XML 架构命名空间 [ http://www.springframework.org/schema/security]定位 Spring NamespaceHandler [ http://www.springframework.org/schema/security]
违规资源:ServletContext 资源 [ /WEB-INF/applicationContext-security.xml]
在 org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
在 org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java :85)
在 org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
Tried everything but can't solve this error. Any help would be appreciated.
尝试了一切,但无法解决此错误。任何帮助,将不胜感激。
EDITI tried added 3.0.2 version of the Spring-Security and got this:
编辑我尝试添加 3.0.2 版本的 Spring-Security 并得到这个:
Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 13 in XML document from ServletContext resource [/WEB-INF/applicationContext-security.xml] is invalid;
nested exception is org.xml.sax.SAXParseException; lineNumber: 13; columnNumber: 11; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'http'. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334
上下文初始化失败
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自 ServletContext 资源 [/WEB-INF/applicationContext-security.xml] 的 XML 文档中的第 13 行无效;
嵌套异常是 org.xml.sax.SAXParseException;行号:13;列数:11;cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素“http”的声明。在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
回答by Bozho
You need a spring-security-config.jaron your classpath.
你spring-security-config.jar的类路径上需要一个。
The exception means that the security:xml namescape cannot be handled by spring "parsers". They are implementations of the NamespaceHandlerinterface, so you need a handler that knows how to process <security:tags. That's the SecurityNamespaceHandlerlocated in spring-security-config
异常意味着security:xml namescape 无法由 spring“解析器”处理。它们是NamespaceHandler接口的实现,因此您需要一个知道如何处理<security:标签的处理程序。那是SecurityNamespaceHandler位于spring-security-config
回答by Carlos
I had the same problem. The only thing that solved it was merge the content of META-INF/spring.handler and META-INF/spring.schemas of each spring jar file into same file names under my META-INF project.
我有同样的问题。解决它的唯一方法是将每个 spring jar 文件的 META-INF/spring.handler 和 META-INF/spring.schemas 的内容合并到我的 META-INF 项目下的相同文件名中。
This two threads explain it better:
这两个线程更好地解释了它:
回答by pards
In my case, this was caused by custom manifest entries added by the maven-jar-plugin.
就我而言,这是由 maven-jar-plugin 添加的自定义清单条目引起的。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestEntries>
<git>${buildNumber}</git>
<build-time>${timestamp}</build-time>
</manifestEntries>
</archive>
</configuration>
</plugin>
Removing the following entries fixed the problem
删除以下条目解决了问题
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
</manifest>

