I have the following code based style aspect which looks for a field level annotation in the code and calls a method with that field as argument. This is how it looks..
public aspect EncryptFieldAspect
{
pointcut encryptStringMethod(Object o, String inString):
call(@Encrypt * *(String))
&& target(o)
&& args(inString)
&& !within(EncryptFieldAspect);
void around(Object o, String inString) : encryptStringMethod(o, inString) {
proceed(o, FakeEncrypt.Encrypt(inString));
return;
}
}
The above method works fine, but I would like to convert it to Annotation based in Spring or AspectJ, something similar to this. Found AspectJ docs a bit confusing any hint would be helpful..
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class MyAspect {
@Around("execution(public * *(..))")
public Object allMethods(final ProceedingJoinPoint thisJoinPoint) throws Throwable {
System.out.println("Before...");
try{
return thisJoinPoint.proceed();
}finally{
System.out.println("After...");
}
}
}