Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring AOP setAdvice only on one specific Method

I have the following class:

package x.y.z;

public class MyClass{
public void someMethod(SomeObject object){
//do somethinng
}

public void {
//do somethinng
}

}

Now I would like to set @PointCutonly on method someMethod(SomeObject object, int param1)

How can I do it?

Update I'm trying

@Pointcut("execution(x.y.z.MyClass.someMethod(x.y.z.SomeObject))") but I'm getting not well formed pointcut exception.
like image 830
danny.lesnik Avatar asked Nov 27 '11 23:11

danny.lesnik


2 Answers

Point cut should be:

target(x.y.z.MyClass) && execution(<RETURN TYPE> someMethod(x.y.z.SomeObject))
like image 76
Michael Wiles Avatar answered Sep 29 '22 00:09

Michael Wiles


Attach AspectJ to your classpath and use maven AOP plugin to compile this Aspect to bytecode, look at this example:

@Aspect
public class IOControlAspect {
    @Around("execution(com...SomeClass.someMethod(*))")
    public Object ioControlWrapper(ProceedingJoinPoint thisJoinPoint) throws Throwable {
        {your code here}
        return thisJoinPoint.proceed();
    }
}
like image 24
Stanislav Levental Avatar answered Sep 29 '22 02:09

Stanislav Levental