首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >spring security未找到WebApplicationContext

spring security未找到WebApplicationContext
EN

Stack Overflow用户
提问于 2011-02-19 04:48:20
回答 1查看 20.5K关注 0票数 16

我是spring security的新手

我有web.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

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

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

<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>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

applicationContext-security.xml

代码语言:javascript
复制
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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="/register.html" access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <intercept-url pattern="/*" access="ROLE_USER, ROLE_ADMIN" />       
    <logout logout-url="/logout"/>
</http>

<beans:bean id="myUserDetailsService" class="labas.spring.service.UserDetailsImp"/>

<authentication-manager>
    <authentication-provider user-service-ref='myUserDetailsService'/>
</authentication-manager>

为什么当我运行它时,我会得到

java.lang.IllegalStateException:未找到WebApplicationContext :未注册ContextLoaderListener?

怎么啦?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-19 04:54:23

您还没有声明webapp的根上下文-您已经添加了contextConfigLocation,但没有添加使用它的侦听器:

代码语言:javascript
复制
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
票数 18
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5046403

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档