Spring 3.0 - 无法找到XML模式命名空间的Spring NamespaceHandler [http://www.springframework.org/schema/security]

Tay*_*ese 176 java spring maven-2 spring-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]
Run Code Online (Sandbox Code Playgroud)

这是我的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>
Run Code Online (Sandbox Code Playgroud)

在我的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>
Run Code Online (Sandbox Code Playgroud)

Tay*_*ese 285

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

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.0.1.RELEASE</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

  • 培根再次被SO救了! (12认同)
  • +1用于解决我的问题.有关spring security 3.0代码库重组的更多信息,请访问:http://blog.springsource.com/2009/06/03/spring-security-300m1-released/ (3认同)

Jam*_*hin 18

尝试部署应用程序时,我有相同的错误消息.在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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

即使您进行了这些更改,也会存在名称空间错误.要摆脱这种情况,请将以下jar文件添加到WEB-INF/lib,然后添加到库中:

  • 弹簧安全ACL-3.1.0.M2.jar
  • 弹簧安全配置,3.1.0.M2.jar
  • 弹簧安全核心3.1.0.M2.jar
  • 弹簧安全标签库,3.1.0.M2.jar
  • 弹簧安全网络3.1.0.M2.jar


Pat*_*era 11

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


小智 8

我用spring-security-config jar它解决了我的问题


Pet*_*kas 6

解决方案绝对不是你的WEB-INF/lib中的"spring-security-config".

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

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

我一直在寻找SO和网络最后一小时寻找这个,所以希望这有助于其他人.