Spring Security异常之You must provide a configuration attribute

    案情描述: 在使用Spring Security框架进行开发的时候,跑出了 “You must provide a configuration attribute”这样的异常,异常详细信息如下:


org.springframework.beans.factory.BeanCreationException : Error creating bean with name ‘favSecurityMetadataSource‘ defined in class path resource [security/spring-security.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.favccxx.favsecurity.security.FavInvocationSecurityMetadataSourceService]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: You must provide a configuration attribute


    案情分析:从上面的异常信息中可以得到“You must provide a configuration attribute”异常发生在自定义实现“FilterInvocationSecurityMetadataSource”的类中。为什么会发生这样的异常呢?通过接口层层深入,我们可以发现原来异常是在 SecurityMetadataSource 接口抛上来的,SecurityMetadataSource 接口的构造函数中需要一个配置参数。


技术分享


    在我们自实现FilterInvocationSecurityMetadataSource接口的类中,我们通常也会写类似“loadResourceMatchAuthority”这样加载资源匹配权限的方法,当发生上面的异常时,应该检查如下图所示的代码区域,设置断点,查找发生问题的主要代码。


技术分享


本文出自 “尘风随影的天空” 博客,请务必保留此出处http://favccxx.blog.51cto.com/2890523/1610609

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。