任何想法可能是什么原因?
找不到 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]
这是我的 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>
在我的 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>
我需要添加一个额外的 Maven 依赖项:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
尝试部署应用程序时出现相同的错误消息。在 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>
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>
即使您进行了这些更改,命名空间错误也会存在。要摆脱这种情况,请将以下 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
我为此苦苦挣扎了一段时间,但这些答案都没有帮助。感谢 user64141 的评论,我意识到 spring.handlers
文件存在问题。
我正在使用 Maven 的 Shade 插件来生成一个胖 jar,并且所有 spring.handlers
(和 spring.schemas
)文件都被每个 Spring 依赖项覆盖。
Maven 站点涵盖了这个确切的问题以及如何通过将文件附加在一起来解决它:
我使用了 spring-security-config jar 它为我解决了这个问题
解决方案绝对是“spring-security-config”,不在您的 WEB-INF/lib 中。
对于我在 Eclipse 中使用 Maven 的项目,事实证明并非所有的 Maven 依赖项都被复制到 WEB-INF/lib。查看项目 -> 属性 -> 部署程序集,只有一些 jar 被复制。
为了解决这个问题,我点击了“添加”,然后点击了“Java Build Path Entires”,最后点击了“Maven Dependencies”。
在过去的一个小时里,我一直在搜索 SO 和网络来寻找这个,所以希望这对其他人有帮助。
一个很好的 Maven 依赖项列表存在于:Spring Site 所需的主要工件是:
spring-security-core Spring-security-web spring-security-config
@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"
在我的情况下,将它们都更改为 3.1 解决了问题
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security/spring-security-3.2.xsd
在我的情况下,我缺少“spring-security-config”jar。
我做了什么:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
和
xsi:schemaLocation="
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
完美地工作。更多Baeldung
如果您的 pom 中已经有所有依赖项,请尝试: 1. 从 'org->springframework' 的 maven 存储库文件夹中删除所有下载的 jar 2. 进行 maven clean build。
我今天遇到了非常相似的问题。由于某种原因,IntelliJ IDEA
在部署应用程序时没有包含 Spring Security jar 文件。我想我应该同意这里的大多数海报。
我在部署到 Virgo 时遇到此错误。解决方案是将其添加到我的捆绑包导入中:
org.springframework.transaction.config;version="[3.1,3.2)",
我注意到在 META-INF 下的 Spring jar 中有一个 spring.schemas 和一个 spring.handlers 部分,并且必须导入它们指向的类(在本例中为 org.springframework.transaction.config.TxNamespaceHandler)。
几分钟前遇到了同样的问题,我在部署程序集中缺少“Maven 依赖”库。我通过 Eclipse 中的“Web 部署程序集”部分添加了它
如果添加依赖项没有解决您的问题,请再次创建 WAR 存档。就我而言,我使用过时的 WAR 文件,没有 security-web 和 security-conf jars
在您的 pom.xml 文件中添加以下依赖项,如果您使用 IntelliJ,则将相同的 jar 添加到 WEB-INF->lib 文件夹....路径是 Project Structure -> Atrifacts -> Select jar from Available Elements pane and double点击。它将添加到相应的文件夹
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
spring-security-cas
jar 时,类似的解决方案也成立。Unable to locate Spring NamespaceHandler for XML schema namespace [xxxxx]
问题的人推荐此 link。我过去有一个similar issue,这对我帮助很大!