ChatGPT解决这个技术问题 Extra ChatGPT

Spring 3.0 - 无法找到 XML 模式命名空间的 Spring NamespaceHandler [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]

这是我的 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>
我在遵循 Spring Pizzashop 教程时遇到了这个问题
这是你完整的 pom.xml 吗?因为那样你很可能会错过一个罐子。

T
Taylor Leese

我需要添加一个额外的 Maven 依赖项:

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.0.1.RELEASE</version>
    </dependency>

+1 解决我的问题。有关 Spring Security 3.0 代码库重组的更多信息,请访问:blog.springsource.com/2009/06/03/spring-security-300m1-released
不错的链接。几个月前我也可以使用它。
培根又被SO救了!
尝试仅使用 spring-security-cas jar 时,类似的解决方案也成立。
我确实向有 Unable to locate Spring NamespaceHandler for XML schema namespace [xxxxx] 问题的人推荐此 link。我过去有一个similar issue,这对我帮助很大!
J
James Jithin

尝试部署应用程序时出现相同的错误消息。在 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


你几乎必须使用 Maven 来启动 Spring。当你不情愿地这样做时,它仍然不起作用!某人,某处正在大笑……这个答案有助于减少我的挫败感。
P
Patrick Herrera

我为此苦苦挣扎了一段时间,但这些答案都没有帮助。感谢 user64141 的评论,我意识到 spring.handlers 文件存在问题。

我正在使用 Maven 的 Shade 插件来生成一个胖 jar,并且所有 spring.handlers(和 spring.schemas)文件都被每个 Spring 依赖项覆盖。

Maven 站点涵盖了这个确切的问题以及如何通过将文件附加在一起来解决它:

http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer


a
abhiram

我使用了 spring-security-config jar 它为我解决了这个问题


P
Peter Sankauskas

解决方案绝对是“spring-security-config”,不在您的 WEB-INF/lib 中。

对于我在 Eclipse 中使用 Maven 的项目,事实证明并非所有的 Maven 依赖项都被复制到 WEB-INF/lib。查看项目 -> 属性 -> 部署程序集,只有一些 jar 被复制。

为了解决这个问题,我点击了“添加”,然后点击了“Java Build Path Entires”,最后点击了“Maven Dependencies”。

在过去的一个小时里,我一直在搜索 SO 和网络来寻找这个,所以希望这对其他人有帮助。


G
George Papatheodorou

一个很好的 Maven 依赖项列表存在于:Spring Site 所需的主要工件是:

spring-security-core Spring-security-web spring-security-config


F
ForestierSimon

@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。
同意这个评论。由于这个原因,我遇到了问题。
X
Xelian

我做了什么:

      <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


a
arviarya

如果您的 pom 中已经有所有依赖项,请尝试: 1. 从 'org->springframework' 的 maven 存储库文件夹中删除所有下载的 jar 2. 进行 maven clean build。


s
shapiy

我今天遇到了非常相似的问题。由于某种原因,IntelliJ IDEA 在部署应用程序时没有包含 Spring Security jar 文件。我想我应该同意这里的大多数海报。


u
user64141

我在部署到 Virgo 时遇到此错误。解决方案是将其添加到我的捆绑包导入中:

org.springframework.transaction.config;version="[3.1,3.2)",

我注意到在 META-INF 下的 Spring jar 中有一个 spring.schemas 和一个 spring.handlers 部分,并且必须导入它们指向的类(在本例中为 org.springframework.transaction.config.TxNamespaceHandler)。


L
LucaEffe

几分钟前遇到了同样的问题,我在部署程序集中缺少“Maven 依赖”库。我通过 Eclipse 中的“Web 部署程序集”部分添加了它


D
David

如果添加依赖项没有解决您的问题,请再次创建 WAR 存档。就我而言,我使用过时的 WAR 文件,没有 security-web 和 security-conf jars


S
Sia

在您的 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>