【问题标题】:Spring 3.0 - Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]Spring 3.0 - 无法找到 XML 模式命名空间的 Spring NamespaceHandler [http://www.springframework.org/schema/security]
【发布时间】:2011-01-10 18:56:03
【问题描述】:

任何想法可能是什么原因造成的?

找不到 Spring XML 模式的 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 吗?因为那样你很可能会错过一个罐子。

标签: java spring maven-2 spring-security


【解决方案1】:

我需要添加一个额外的 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,这对我很有帮助!
【解决方案2】:

我在尝试部署应用程序时收到了相同的错误消息。在 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。当你不情愿地这样做时,它仍然不起作用!某人,某处正在大笑……这个答案有助于减少我的挫败感。
【解决方案3】:

我为此苦苦挣扎了一段时间,但这些答案都没有帮助。感谢 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

【讨论】:

    【解决方案4】:

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

    【讨论】:

      【解决方案5】:

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

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

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

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

      【讨论】:

        【解决方案6】:

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

        1. 弹簧安全核心
        2. Spring-security-web
        3. spring-security-config

        【讨论】:

          【解决方案7】:

          @James Jithin - 当您在 xsi:schemaLocation 中有两个不同版本的 bean 和安全模式时,也会出现此类异常。您粘贴的 sn-p 中就是这种情况:

          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 解决了问题

          【讨论】:

          • 同意此评论。由于这个原因,我遇到了问题。
          【解决方案8】:

          我做了什么:

                <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

          【讨论】:

            【解决方案9】:

            如果您的 pom 中已经有所有依赖项,请尝试:
            1。从 'org-> springframework' 的 maven 存储库文件夹中删除所有下载的 jar
            2。制作一个 Maven 干净的构建。

            【讨论】:

              【解决方案10】:

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

              【讨论】:

                【解决方案11】:

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

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

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

                【讨论】:

                  【解决方案12】:

                  【讨论】:

                    【解决方案13】:

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

                    【讨论】:

                      【解决方案14】:

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

                      【讨论】:

                        【解决方案15】:

                        在您的 pom.xml 文件中添加以下依赖项,如果您使用 IntelliJ,则将相同的 jar 添加到 WEB-INF->lib 文件夹....路径是 Project Structure -> Atrifacts -> 从可用元素中选择 jar窗格并双击。它将添加到相应的文件夹中

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

                        【讨论】:

                          猜你喜欢
                          • 2011-11-03
                          • 2019-01-27
                          • 2013-10-04
                          • 2018-05-16
                          • 2023-03-03
                          • 2015-02-25
                          相关资源
                          最近更新 更多