Results 1 to 3 of 3

Thread: Simple AOP Question

  1. #1
    Join Date
    Jun 2005
    Location
    Boston MA
    Posts
    4

    Default Simple AOP Question

    Hello;

    I am simply trying to do some AOP on a particular object and on a particular method of that object. I can get the before() advice to work for every method on my object, but I just want to get it to work for just one execute() method. I am sure there is a way to do this but I cannot figure this out based on my spring configuration. Here is my configuration

    <bean id="batchProcessMain"
    class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="target" ref="batchProcessMainTarget"/>
    <property name="interceptorNames">
    <list>
    <value>batchEventTrackerInterceptor</value>
    </list>
    </property>
    </bean>


    <bean id="batchProcessMainTarget"
    class="com.putnam.fams.batch.BatchProcessMain">
    </bean>

    <bean id="batchEventTrackerInterceptor"
    class="com.putnam.fams.batch.aop.BatchEventTracker Interceptor">
    <property name="eventTrackerDao" ref="eventTrackerDao"/>
    </bean>

    Here is my Advice class
    public class BatchEventTrackerInterceptor
    implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice {

    /**
    *
    */
    public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable {

    if( "execute".equals( arg0.getName() ) ) {
    log.info(" This is the execute() Method Process" );
    }
    }

    In my BatchEventTrackerInterceptor I can determine the method easy enough, but I would like to configure this outside of my code.



    Can someone please point out what I am doing wrong?
    Thanks
    Peter

    I determined the problem. I needed to add the following to my spring config to get the execute to work;


    <bean id="batchEventTrackerAdvisor"
    class="org.springframework.aop.support.RegexpMetho dPointcutAdvisor">
    <property name="advice">
    <ref local="batchEventTrackerInterceptor"/>
    </property>
    <property name="pattern">
    <value>execute</value>
    </property>
    </bean>
    Last edited by pdelaney; Nov 15th, 2007 at 11:25 AM. Reason: Determined the solution
    Peter Delaney
    Senior Technologist
    delaneymichaelpeter@gmail.com

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Use a RegExpMethodAdvisor around your advice OR use the aop config to define an AspectJ pointcut which matches your needs.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jun 2005
    Location
    Boston MA
    Posts
    4

    Default AOP problme

    Thanks found the problem thanks for the help!!
    Peter Delaney
    Senior Technologist
    delaneymichaelpeter@gmail.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •