代码之家  ›  专栏  ›  技术社区  ›  Taylor Leese

Spring 3.0-找不到XML架构命名空间的Spring命名空间处理程序[http://www.springframework.org/schema/security]

  •  174
  • Taylor Leese  · 技术社区  · 15 年前

    有什么想法是什么原因造成的?

    < Buff行情>

    找不到弹簧 XML架构的命名空间处理程序 命名空间 [ http://www.springframework.org/schema/security]。

    org.springframework.web.context.contextloader initwebapplicationContext:context初始化失败
    org.springframework.beans.factory.parsing.beanDefinitionParsingException:配置问题:找不到XML架构命名空间的Spring命名空间处理程序[http://www.springframework.org/schema/security]
    有问题的资源:servletcontext resource[/web-inf/applicationcontext.xml]
    < /代码> 
    
    

    这是我的applicationContext.xml:。

    <?xml version=“1.0”encoding=“utf-8”?gt;
    <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中,我有:

    依赖关系 <groupid>org.springframework.security</groupid> <artifactid>Spring安全核心</artifactid> <version>3.0.1.版本</version> </dependency> <相关性> <groupid>org.springframework.security</groupid> <artifactid>Spring安全OpenID</artifactid> <version>3.0.1.版本</version> </dependency> < /代码> <命名空间 [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>
    
    15 回复  |  直到 8 年前
        1
  •  285
  •   Taylor Leese    15 年前

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

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>3.0.1.RELEASE</version>
        </dependency>
    
        2
  •  18
  •   James Jithin    14 年前

    我在尝试部署应用程序时收到了相同的错误消息。在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
    • 弹簧-安全-核心-3.1.0.m2.jar
    • spring-security-taglibs-3.1.0.m2.jar
    • spring-security-web-3.1.0.m2.jar
        3
  •  10
  •   Patrick Herrera    11 年前

    我为此挣扎了一段时间,但这些答案都无济于事。感谢你的评论 用户64141 我意识到 spring.handlers 文件夹。

    我正在使用maven的shade插件生成一个胖罐子,以及 弹簧处理器 (和) spring.schemas )每个Spring依赖项都覆盖了文件。

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

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

        4
  •  8
  •   abhiram    12 年前

    我使用了Spring安全配置jar,它为我解决了问题

        5
  •  6
  •   Peter Sankauskas    13 年前

    解决方案肯定是“Spring安全配置”,而不是在WEB-INF/lib中。

    对于我在Eclipse中使用Maven的项目,结果并不是所有Maven依赖项都被复制到WEB-INF/lib。查看项目->属性->部署程序集时,只复制了一些JAR。

    为了解决这个问题,我点击了“添加”,然后单击“Java构建路径集中”,最后单击“Maven依赖”。

    我一直在搜索So和Web,在过去的一个小时里一直在寻找它,所以希望它能帮助其他人。

        6
  •  3
  •   George Papatheodorou    12 年前

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

    1. 弹簧安全芯
    2. Spring安全Web
    3. 弹簧安全配置
        7
  •  3
  •   ForestierSimon    12 年前

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

        8
  •  1
  •   Xelian    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
  •  0
  •   arviarya    12 年前

    如果您的POM中已经有了所有依赖项,请尝试:
    1。从“org->springframework”的maven存储库文件夹中删除所有下载的jar
    2.第2条。做一个整洁的小人。

        10
  •  0
  •   shapiy    12 年前

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

        11
  •  0
  •   user64141    12 年前

    我在部署到处女座时遇到了这个错误。解决方案是将此添加到我的包导入:

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

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

        12
  •  0
  •   Avinash    11 年前
        13
  •  0
  •   LucaEffe    9 年前

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

        14
  •  0
  •   David stands with Ukraine    8 年前

    如果添加依赖项还没有解决您的问题,请重新创建war存档。在我的例子中,我使用了过时的没有安全web和安全conf jars的war文件

        15
  •  0
  •   Sia    8 年前

    在pom.xml文件中添加以下依赖项,如果使用intellij,则将相同的jar添加到WEB-INF->lib文件夹….路径是项目结构->atrifacts->从“可用元素”窗格中选择jar并双击。它将添加到相应的文件夹中

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