1

Pointcut declaration:

@Pointcut(value="com.someapp.someservice.someOperation() && args(t,req)",argNames="t,req")
private void logOperationArg(final String t,final String req)
{
}

Advice Declaration not compiling:

@Before(value="logOperationArg(t,req)")
public void logBeforeOperationAdvice(JoinPoint jp, final String t, final String req){
...
}

When compiling Aspect with Aspectj-maven-plugin (1.5 version), have error "can not build thisJoinPoint lazily for this advice since it has no suitable guard [Xlint:noGuardForLazyTjp]"

But the same advice compiles without JoinPoint argument.

Advice Declaration compiling:

@Before(value="logOperationArg(t,req)")
public void logBeforeOperationAdvice(final String t, final String req){
...
}
cb4
  • 6,689
  • 7
  • 45
  • 57
user1044173
  • 33
  • 1
  • 7
  • how to you execute your logOperationArg()? Make it public... Also use execution() instead of value=... – solvator Jan 05 '14 at 08:06

1 Answers1

2

Spring AOP only supports method join points because it is based on dynamic proxies which creates proxied object if it is needed (for example if you are using ApplicationContext, it will be created after beans are loaded from BeanFactory)

Use execution() statement to match join points which are methods execution.

For example:

class LogAspect {

@Before("execution(* com.test.work.Working(..))")
public void beginBefore(JoinPoint join){

System.out.println("This will be displayed before Working() method will be executed");
}

And now how to declare your BO:

//.. declare interface

then:

class BoModel implements SomeBoInterface {

public void Working(){
System.out.println("It will works after aspect");
     }
}

execution() statement is a PointCut expression to tell where your advice should be applied.

If you like to use @PointCut, you can do something like this:

class LogAspect {

//define a pointcut
@PointCut(
        "execution(* com.test.work.SomeInferface.someInterfaceMethod(..))")
     public void PointCutLoc() {
}

@Before("PointCutLoc()")
public void getBefore(){
System.out.println("This will be executed before someInterfaceMethod()");
      }

}

Part2:

Also,the Error shows that you haven't put a guard on your advice. Technically guard makes your code faster, because you do not need construct thisJoinPoint everytime you execute it. So, if it does not make sense you can try to ignore it

canNotImplementLazyTjp = ignore
multipleAdviceStoppingLazyTjp=ignore
noGuardForLazyTjp=ignore
solvator
  • 371
  • 1
  • 6
  • 12
  • As per Spring AOP doc http://docs.spring.io/spring/docs/3.0.x/reference/aop.html#aop-advice-before Pointcut declaration can be done using method name too – user1044173 Jan 05 '14 at 08:10
  • It can, if you use it in some annotation like @AfterThrowing, but you are not doing it. Because of this, you should use execution() statement to express your pointcut and match your join points. So execution() will take your method name (with all path), to know where to apply your advice. ;) – solvator Jan 05 '14 at 08:13