2011-05-08 42 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