发现了Mo webApplication Context,没有上下文和

时间:2014-02-26 06:35:48

标签: spring spring-security

我已经配置了spring-security.xml:

<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.0.xsd">
    <http auto-config="true">
    <intercept-url pattern="/loginPage" access="IS_AUTHENTICATED_ANONYMOUSLY" />

            <logout logout-success-url="/errorPage" logout-url="//errorPage"/>
            <session-management invalid-session-url="/home?invalid=true" />
        </http>

我在web.xml中添加了以下代码:

<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>*.do</url-pattern>
</filter-mapping>

然后我收到了这个错误:

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:251)

任何人都可以说出这个错误吗?

1 个答案:

答案 0 :(得分:0)

你有你的上下文XML文件,没关系。但是你还需要以某种方式告诉Spring加载该文件。对于ROOT上下文(安全配置所属的位置),这可以通过web.xml中的以下配置来完成:

<listener>    
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    
</listener>    
<context-param>    
    <param-name>contextConfigLocation</param-name>    
    <param-value>/WEB-INF/spring-security.xml</param-value>    
</context-param>

请同时查看official documentation on this topic