coldfusionaopcoldspring

How can I configure AOP in ColdSpring 2.0?


I'd like to implement some before and after method advisors in Coldspring 2.0, and I'd like to use the new schema for AOP and the new autoproxying feature. Unfortunently, the Narwhal documentation for AOP is currently a cliffhanger. Can anyone give me an example of a Coldspring 2.0 configuration file that uses the AOP schema?


Solution

  • I just finished off 1 more section in the AOP documentation, but in the mean time, here are a few examples to get the ball rolling.

    This is an example of setting up around advice. It calls the method timeMethod on the object timer, that matches the pointcut of execution(public * *(..)), which translated to: a method execution, that is public, that returns anything, that is named anything, and takes any arguments, of any types. Essentially, it matches everything.

    <?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>
    

    The important piece to note, is that while Time.cfc is just a plain ol' CFC, for it to do the around advice, the method that is being used has to take a MethodInvocation as an argument, like so:

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

    But there you go, there is an example of using AOP in CS2.

    You can still use MethodInterceptors and the like as well, but you will be using <aop:advisor> rather than <aop:aspect>.

    But overall, I'm working on the CS2 AOP documentation right now, so it should get filled out in the next day or so.