关于使用springframework.security的问题

XuePeng77 发布于 2016/09/26 23:21
阅读 302
收藏 0

今天想试试spring提供的security,于是下载了jar包进行配置:

spring-security-config-4.1.3.RELEASE

spring-security-core-4.1.3.RELEASE

spring-security-web-4.1.3.RELEASE

跟着教程走,通过java代码进行配置DelegatingFilterProxy,让类继承AbstractSecurityWebApplicationInitializer。

package cn.net.bysoft.config;

import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;

public class SecurityWebInitializer extends AbstractSecurityWebApplicationInitializer {

}
按教程说AbstractSecurityWebApplicationInitializer实现了WebApplicationInitializer,因此spring会发现它,要注册DelegatingFilterProxy,我们不需要重载任何方法就可以。

结果开启tomcat后报错了:

九月 26, 2016 11:20:14 下午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter springSecurityFilterChain
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1060)
	at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326)
	at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:235)
	at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:199)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:109)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4917)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5609)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)



没有找到springSecurityFilterChain这个bean,求助一下,谢谢大家!

加载中
0
找骨头的啊呜
找骨头的啊呜

看楼主的信息,没有看出什么特别的错误. 但是本人尝试是没有问题的啊,你再按照官方的教程试试看.

应该不会有错的.

http://docs.spring.io/spring-security/site/docs/3.2.x/guides/hellomvc.html

0
逝水fox
逝水fox

你在web.xml定义的过滤器DelegatingFilterProxy名字叫springSecurityFilterChain,所以他会在当前的WebApplicationContext中寻找这个同名bean作为真正的过滤器实现。

而springSecurityFilterChain这个bean是spring security默认生成的过滤器链的名字,如果找不到这个bean,需要检查两个方面:

1. 需要使用<sec:http>或@EnableWebSecurity注解启用Web安全才会创建。

2. 如果你有使用Spring MVC,一定注意Spring Security过滤器是脱离在mvc外层的,所以相关的定义一定要在contextConfigLocation定义的配置文件里定义,由ContextLoaderListener来创建ApplicationContext来管理,而不是MVC的DispatcherServlet的配置文件。

0
LucEsape
LucEsape
http config 漏了
返回顶部
顶部