When describing a named point cut, the following format was described:
Is it possible to write arguments in ()
and specific actions in {}
?
I have looked into many things and found only the following format explanations.
@Pointcut("execution(**.*test.*(...))")")
public void myTest(){}
I think there are some oversights, so could you please let me know the location if there is an explanation for either of them?
Thank you for your cooperation.
You're asking me if I can write arguments in ()
of public void myTest(){}
and specific actions in {}
.If so, the answer is that both arguments and method processing can only be written when a specific point-cut expression is written.
This part is handled by a library called AspectJ (even with the Spring framework) and is described in the document.
https://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj-pcadvice.html
First, write about method arguments.Here is an excerpt from the above web page.
The parameters of the method response to the parameters of the pointcut.
Translation: The method argument matches the point cut argument.
In other words, if you write arguments in the point-cut expression, you write the same arguments in the method.
There is an example on the above web page.
@Pointcut("call(*.*(int))&args(i)&target(callee)")
void anyCall(inti, Focallee){}
First, we write the argument i
in args()
, so we write inti
in the method argument. In addition to specifying arguments like args()
, we also use the name calle
in for the object called in
There is also
this()
, where you write method arguments.
Next is the method body.Here is an excerpt from the previous page.
As a general rule, the @Pointcut unknown method must have an empty method body and must not have any flows cause.
Translation: As a general rule, a method with @Pointcut must have an empty method body and cannot have any threads clause.
Therefore, it is not possible to write actions on the method body.
However, there is something called if()
and you only write actions on the method body when you use it.Here's another excerpt.
@Pointcut("call(*.*(int))&args(i)&if()")
public static boolean someCallWithIfTest(inti){
return i>0;
}
Write the if()
conditional branching action on the method body.This is the only case that can be processed.
© 2024 OneMinuteCode. All rights reserved.