歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Spring Security異常之You must provide a configuration attribute

Spring Security異常之You must provide a configuration attribute

日期:2017/3/1 9:33:19   编辑:Linux編程

案情描述: 在使用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”這樣加載資源匹配權限的方法,當發生上面的異常時,應該檢查如下圖所示的代碼區域,設置斷點,查找發生問題的主要代碼。

Spring Security 學習之數據庫認證 http://www.linuxidc.com/Linux/2014-02/97407.htm

Spring Security 學習之LDAP認證 http://www.linuxidc.com/Linux/2014-02/97406.htm

Spring Security 學習之OpenID認證 http://www.linuxidc.com/Linux/2014-02/97405.htm

Spring Security 學習之X.509認證 http://www.linuxidc.com/Linux/2014-02/97404.htm

Spring Security 學習之HTTP基本認證和HTTP摘要認證 http://www.linuxidc.com/Linux/2014-02/97403.htm

Spring Security 學習之HTTP表單驗證 http://www.linuxidc.com/Linux/2014-02/97402.htm

Copyright © Linux教程網 All Rights Reserved