2011-05-08 39 views

回答

2

我剛剛在AOP文檔中完成了另外1個部分,但同時,這裏有幾個例子可以讓球滾動。

這是圍繞建議設置的示例。它調用方法timeMethod對象計時器,是的execution(public * *(..))的切入點,從而轉化到比賽上:的方法執行,這是公開的,返回什麼,就是取名,並採取任何參數,任何類型。基本上,它匹配一切。

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.coldspringframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:aop="http://www.coldspringframework.org/schema/aop" 
    xsi:schemaLocation="http://www.coldspringframework.org/schema/beans http://coldspringframework.org/schema/coldspring-beans-2.0.xsd 
    http://www.coldspringframework.org/schema/aop http://www.coldspringframework.org/schema/coldspring-aop-2.0.xsd" 
    > 

<!-- AOP configuration --> 
<aop:config> 
    <aop:aspect ref="timer"> 
     <aop:around method="timeMethod" 
      pointcut="execution(public * *(..))"/> 
    </aop:aspect> 
</aop:config> 


<bean name="timer" class="05_AOP.Timer" /> 
<bean name="longTime" class="05_AOP.LongTime" /> 

</beans> 

要注意的重要的部分,是,雖然Time.cfc只是一個簡單的醇」 CFC,爲它做的環繞通知,正在使用具有採取的MethodInvocation作爲該方法參數如下:

public any function timeMethod(required MethodInvocation invocation) 
{ 
    ... 
} 

但是你去了,有一個在CS2中使用AOP的例子。

您仍然可以使用MethodInterceptors等,但您將使用<aop:advisor>而不是<aop:aspect>

但總的來說,我現在正在編寫CS2 AOP文檔,所以應該在第二天左右填寫。

+0

感謝Mark,我一直在研究Spring框架,AOP-2.0模式和Coldspring 2.0 API文檔中的例子,試圖找出這個例子。期待新的文檔。享受聲譽,無論如何我欠你幾分。 – 2011-05-13 16:14:06