日期:2014-5-16 浏览次数:20066次

css鐨勬簮鐮佸涔犳棩蹇?-spring IoC, AOP

鍩轰簬spring 3.1.0.
IoC鍜孉OP鏄痵pring鐨勫熀纭€銆傚厛鐪婭oC銆傛帴鍙d互BeanFactory鍜孉pplicationContext涓轰腑蹇冿紝abstractBeanFactory鏈夊緢澶氬疄鐜般€備粠ClassPathXmlApplicationContext寮€濮嬨€?娣诲姞浜唕esource绠$悊)銆備粠refresh()寮€濮嬨€?br>鍒濆鍖?br>聽 Resource Loader
聽 load BeanDefinition
聽聽聽 Reader
聽聽聽 register
聽聽聽聽聽 documentReader
聽聽聽聽聽 BeanDefinitionParserDelegate
聽 Registry(FactoryBeanRegistrySupport.ConcurrentHashMap)
渚濊禆娉ㄥ叆(getBean), abstractBeanFactory.getObjectForBeanInstance(),
FactoryBeanRegistrySupport.getObjectFromFactoryBean(),doGetObjectFromFactoryBean(),娉ㄦ剰杩欓噷factory.getObject();瀹炵幇FactoryBean.

鍒濆鍖栧彧鏄痩oad beanDefinition锛屾敞鍏ュ湪getBean鏃跺彂鐢燂紝鑻ユ湁寰幆寮曠敤瀵箂ingleton涓嶄細鏈夐棶棰橈紝瀵筽rototype鏈夋娴嬶紝鑻ヨ寮曠敤bean鍒欏湪creating涓垯鎶涘紓甯搞€?br>
--AOP
姒傚康锛歛dvice, pointcut, advisor.
浠roxyFactoryBean涓轰緥銆傚畠鏄竴涓狟eanFactoryAware鍙緱鍒癇eanFactory锛屽悓鏃跺湪init Bean鐨勬椂鍊欎細璋冨叾getObject鏂规硶鍥犳鍙疄鐜板叾Factory鐨勪綔鐢ㄨ繑鍥瀙roxy銆俛opproxy鏈変袱绉嶏細jdk**proxy, cglib**proxy锛屼互涓嶅悓鐨勬柟寮?鍒嗗埆璋僫nvoke, intercept)鍦ㄥ叾涓皟鐢≧eflectiveMethodInvocation.proceed()銆傝嫢娌℃湁advise鍒欑洿鎺ヨ皟鐢ㄦ柟娉曪紝鏈塵akeAccessible銆?/p>

鏉ョ湅proceed()銆備粠chain涓彇matcher(advisor)鎴杋nterceptor锛屽墠鑰呮牴鎹叾matcher璋僫nterceptor鍚庤€呯洿鎺ヨ皟銆?/p>

鏉ョ湅chain鎬庝箞浠庨厤缃腑鏉ャ€傚叾鏉ヨ嚜***Proxy涓殑AdvisedSupport advised;浠巊etInterceptorsAndDynamicInterceptionAdvice鍏ユ墜锛屽叾浠嶥efaultAdvisorChainFactory涓锛岀敱AdvisorAdapterRegistry瀹屾垚锛岃€屽弬鏁版潵鑷簬AdvisedSupport鐨刟dvisors.杩欎釜advisors瑕佸洖鍒?strong>ProxyFactoryBean.initializeAdvisorChain(),浠巄eanFactory.getBean()鍙栧緱advice骞禷dd, ProxyBeanFactory鏄竴涓猘utowirecapableBeanFactory鎵€浠ュ湪init瀹冭嚜韬殑鏃跺€欎細琚缃瓸eanFactory鏈韩锛岀粰浜堝畠鎰熺煡factory鐨勮兘鍔涖€?/p>

娉ㄦ剰浠ヤ笂姒傚康锛屾垜浠缁囧叆鐨勬槸advice锛屼絾鏄痗hain閲屾槸interceptor锛岃繖閲屾湁涓嶄竴鑷淬€傝繖灏辨槸adapter鐨勪綔鐢ㄣ€備笁绉峚dviceAdapter灏哸dvice鍖呰鎴恑nterceptor锛屾斁鍒癱hain涓€傚寘瑁呯殑鏃跺€欏垎鍒畬鎴恇efore, after, around绛夊姛鑳姐€?/p>