在Spring的官方論壇中找到一個帖子:http://forum.springframework.org/showthread.php?t=11242&highlight=objectDefinitionSource
其中提到:
引用
The PropertyEditorManager uses three techniques for locating an editor for a given type. First, it provides a registerEditor method to allow an editor to be specifically registered for a given type. Second it tries to locate a suitable
class by adding "Editor" to the full qualified classname of the given type (e.g. "foo.bah.FozEditor"). Finally it takes the simple classname (without the package name) adds "Editor" to it and looks in a search-path of packages for a matching class.
PropertyEditorManager是java.beans包中的一個類,難道其中的根據“類型名稱+Editor”來查找屬性相應的編輯器(姑且這麼翻譯)的機制是Java早就擁有的?查看JDK中PropertyEditorManager相關的內容,果然找到上面的那段話!
原來是這樣!難怪在Spring、Acegi的源碼中都找不到註冊或調用FilterInvocationDefinitionSourceEditor的代碼。我以爲這是Spring或Acegi提供的機制,原來是Java的標準機制!
至此可以理解讀取配置並給屬性賦值的過程大致如下:
1.Spring讀取Acegi相關的配置,知道需要把類似
引用
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/secured/usermanage/**=ROLE_TEST
/secured/**=ROLE_USER
PATTERN_TYPE_APACHE_ANT
/secured/usermanage/**=ROLE_TEST
/secured/**=ROLE_USER
的內容賦值給bean filterSecurityInterceptor的objectDefinitionSource屬性
2.Spring知道filterSecurityInterceptor的objectDefinitionSource屬性的類型爲 FilterInvocationDefinitionSource,查找該類型的編輯器。因爲Acegi並未爲該類型顯式地註冊編輯器(查Acegi代碼可知),Spring應用上面的規則查到相應的編輯器爲FilterInvocationDefinitionSourceEditor
3.Spring實例化FilterInvocationDefinitionSourceEditor,並調用它完成後續的讀取配置並給屬性賦值的工作