0

I'm very new to Spring-Aspect. In fact, I just need to make a fix, while never implemented with aspect before. So, I have the following classes (not real names :D):

  1. Validate in package com.my which calls
  2. ValidateService which calls
  3. DAO

What I need is an aspect, that will be called only if call to DAO methods (say add, create etc.) has it's deep origin from Validate class. Like the following:

* com.my..*.*(..) -> ValidateService.validate() -> [some other classes may be envolved] -> DAO.add(..)

So I am interested in this part:

* com.my..*.*(..) -> [whatever] -> DAO.add(..)

Tried within, call, execute but no luck. Can someone help? Using Spring Aspect 1.7.0

Many thanks in advance.

1 Answers1

0

It's been a few years since I wrote AspectJ pointcuts, but I think you are missing using the cflow pointcut descriptor. It takes one argument, which is itself the pointcut. The pointcut resolves to true when execution is under the control flow (cflow) of the pointcut that is passed in.

So, you want to do something like this:

pointcut daoCall() : call(* * DAO.*(..)) &&
  cflow(within(ValidateService.validate()));

I may have some of the syntax muddled. So, take a look at the docs on cflow, but above is the basic idea.

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148