我想在ColdSpring2.0中实现一些之前和之后的方法顾问,我想使用面向方面编程的new schema和新的自动代理功能。不幸的是,纳瓦尔的documentation for AOP目前是一个扣人心弦的东西。谁能给我一个使用AOP模式的ColdSpring2.0配置文件的例子?
发布于 2011-05-13 22:59:21
我刚刚完成了AOP文档中的另一个部分,但同时,这里有几个示例来让我们开始工作。
这是一个围绕建议设置的示例。它在对象定时器上调用方法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只是一个简单的ol,但为了让它做周围的建议,正在使用的方法接受MethodInvocation作为参数,如下所示:
public any function timeMethod(required MethodInvocation invocation)
{
...
}但是现在,这里有一个在CS2中使用面向方面编程的示例。
您仍然可以使用MethodInterceptors等工具,但您将使用<aop:advisor>而不是<aop:aspect>。
但总体而言,我现在正在编写CS2 AOP文档,所以应该在第二天左右完成。
发布于 2011-05-25 07:34:18
单据发布!http://sourceforge.net/apps/trac/coldspring/
https://stackoverflow.com/questions/5925044
复制相似问题