我写使用弹簧的安全性和弹簧-MVC与注释基于配置(@Secured)小的web应用。 为了有工作,我不得不分头行动弹簧安全配置:
APP-context.xml中(包括在web.xml中的contextConfigLocation的)
<security:http auto-config="true"/>
APP-servlet.xml中(弹簧MVC的DispatcherServlet负载的情况下)
<security:global-method-security secured-annotations="enabled"/>
我为什么要拆分这些吗? 当我把所有的安全配置在app-context.xml中的@Secured注解似乎被忽略,所以你不需要进行登录访问@Secured控制器方法。
当我把它们都放在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)
我不明白这一点:/