4

我正在尝试做一些基本的弹簧安全示例。但是经过大量的尝试和网上的各种建议,仍然无法解决问题。它给了我以下错误。

09:54:31,640 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-4) Context initialization failed: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring Namesp
aceHandler for XML schema namespace [http://www.springframework.org/schema/security]
Offending resource: ServletContext resource [/WEB-INF/springapp-security.xml]

        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:316) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1416) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) [org.springframework.web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) [org.springframework.web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131) [org.springframework.context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522) [org.springframework.context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436) [org.springframework.context-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) [org.springframework.web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) [org.springframework.web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [org.springframework.web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.10.Final.jar:]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.10.Final.jar:]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [rt.jar:1.6.0_24]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.6.0_24]
        at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_24]

09:54:31,796 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/Trial]] (MSC service thread 1-4) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener:
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/springapp-security.xml]

        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

我正在使用的罐子是

org.springframework.aop-3.1.0.RELEASE.jar
org.springframework.asm-3.1.0.RELEASE.jar
org.springframework.aspects-3.1.0.RELEASE.jar
org.springframework.beans-3.1.0.RELEASE.jar
org.springframework.context-3.1.0.RELEASE.jar
org.springframework.context.support-3.1.0.RELEASE.jar
org.springframework.core-3.1.0.RELEASE.jar
org.springframework.expression-3.1.0.RELEASE.jar
org.springframework.jdbc-3.1.0.RELEASE.jar
org.springframework.jms-3.1.0.RELEASE.jar
org.springframework.orm-3.1.0.RELEASE.jar
org.springframework.test-3.1.0.RELEASE.jar
org.springframework.transaction-3.1.0.RELEASE.jar
org.springframework.web-3.1.0.RELEASE.jar
org.springframework.web.servlet-3.1.0.RELEASE.jar
spring-batch-core-2.1.8.RELEASE.jar
spring-batch-infrastructure-2.1.8.RELEASE.jar
spring-security-acl-3.1.0.RELEASE.jar
spring-security-config-3.1.0.RELEASE.jar
spring-security-core-3.1.0.RELEASE.jar
spring-security-taglibs-3.1.0.RELEASE.

jar spring-security-web-3.1.0.RELEASE.jar

在 web.xml 我有

<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/springapp-security.xml</param-value>
    </context-param>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

springapp -security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:security="http://www.springframework.org/schema/security"
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 "> 
    <security:http auto-config="true">
        <security:intercept-url pattern="*.htm" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
    </security:http>
    <security:authentication-manager>
        <security:authentication-provider>
            <security:user-service>
                <security:user name="rod" password="koala" authorities="supervisor, teller, user" />
                <security:user name="dianne" password="emu" authorities="teller, user" />
                <security:user name="scott" password="wombat" authorities="user" />
                <security:user name="peter" password="opal" authorities="user" />
            </security:user-service>
        </security:authentication-provider>
    </security:authentication-manager>

</beans

>

4

1 回答 1

2

每件事看起来都很好。仔细检查帽子spring-security-config.jar真的是正确的!

于 2012-05-13T12:42:37.313 回答