【发布时间】:2011-01-08 01:25:59
【问题描述】:
我使用 spring-security 和 spring-mvc 以及基于注释的配置 (@Secured) 编写了一个小型 webapp。为了完成这项工作,我不得不拆分 spring-security 配置:
app-context.xml(包含在 web.xml 的 ContextConfigLocation 中)
<security:http auto-config="true"/>
app-servlet.xml(spring-mvc 的 dispatcherservlet 加载这个)
<security:global-method-security secured-annotations="enabled"/>
为什么我必须把这些分开?当我将所有安全配置放在 app-context.xml 中时,@Secured 注释似乎被忽略了,因此您无需登录即可访问 @Secured Controller 方法。
当我把它全部放在 app-servlet.xml 中时,会引发以下异常...
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1041)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:273)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1008)
at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:217)
at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:145)
at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:179)
我不明白:/
【问题讨论】:
标签: java spring spring-mvc spring-security