?
このドキュメントでは、 php中國語ネットマニュアル リリース
元數(shù)據(jù)屬性最有用的就是與Spring AOP聯(lián)合使用。這提供了一個類似.NET的編程模型:聲明式服務(wù)會自動提供給聲明了元數(shù)據(jù)的屬性。 這些元數(shù)據(jù)屬性可以被框架支持,比如聲明式事務(wù)管理,同時也能定制。
基于Spring AOP的自動代理功能,配置可能如下所示:
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> <property name="transactionInterceptor" ref="txInterceptor" /> </bean> <bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributeSource"> <bean class="org.springframework.transaction.interceptor.AttributesTransactionAttributeSource"> <property name="attributes" ref="attributes" /> </bean> </property> </bean> <bean id="attributes" class="org.springframework.metadata.commons.CommonsAttributes" />
這里的基本原理與AOP章節(jié)關(guān)于自動代理的討論類似。
最重要的bean定義是自動代理的creator和advisor。注意實(shí)際的bean名稱并不重要,重要的是它們的類。
org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator
的bean定義會根據(jù)匹配advisor實(shí)現(xiàn)來自動通知("auto-proxy")當(dāng)前工廠中的所有bean實(shí)例。
這個類對屬性一無所知,只是依賴于advisor匹配的切入點(diǎn),而切入點(diǎn)了解這些屬性。
因此我們只需要一個能提供基于屬性的聲明式事務(wù)管理的AOP advisor。
這樣還能添加自定義的advisor實(shí)現(xiàn),它們能被自動運(yùn)算并應(yīng)用。 (如果有必要,你也可以使用這樣的advisor,它的切入點(diǎn)還能匹配那些相同自動代理配置中除屬性以外的條件。)
最后,屬性
bean是Commons Attributes中的Attributes的實(shí)現(xiàn)。
把它替換為其它的org.springframework.metadata.Attributes
接口實(shí)現(xiàn),就可以從另外的源獲得屬性了。