These two days in looking at the various syntax of AOP ASPECTJ, found that there are two concepts of args and arg-names is easy to confuse, the Internet is basically not clear, so try it out, find it or try it better understanding
First, the conclusion:
Args is used with execution to filter the method to be proxied, if not with arg-names, then the usage is the args (class name, class name ...). )。 If and arg-names (parameter name 1, parameter name 2 ...) Together, the usage is args (parameter 1, parameter 2 ...), where the type of parameter 1 and parameter 2 is determined by the parameters of the method represented by Arg-names
Arg-names is used in conjunction with the Proxy method (that is, the method you want to add before or after the proxy method) arg-names (parameter name 1, parameter name 2 ...) where the parameter name 1 parameter name 2 and the proxy method's parameter name is one by one corresponding
As for @args, it is used for specifying annotations on parameters, but rather better to distinguish
As an example,
First define a class to be proxied:
public interface someinterface{public void Targetfunction (String St, Integer in); public class target implements someinterface{public void Targetfunction (String St, Integer in) {
System.out.println ("I am a proxy class");
}}
Then you define the proxy class.
public class aspect{public void Aspectfunction (Integer in, String St) {
System.out.println ("I am the proxy class, there are two parameters:" + st + "" + in);
}
Then define the XML file:
<bean id= "Targetclass" class= "target"/><bean id= "Aspectclass" class= "aspect"/><aop:config> <aop:aspect id = "ASP1" ref= "Aspectclass" > <aop:after pointcut= "Execution (* *.targetfunction. (..) and Args (String,integer)) "method=" Aspectfunction "/> </aop:aspect> <aop:aspect id =" ASP2 "ref=" Aspectclass "> <aop:after pointcut=" Execution (* *.targetfunction. (..) and args (st,in)) "Method=" Aspectfunction "arg-names=" St,in "/> </aop:aspect></aop:config>
As shown in the XML file, arg is defined in Pointcut, and arg-names is defined in the cut-in position after.
Args is used with execution to filter the method to be proxied, if not with arg-names, then the usage is the args (class name, class name ...). )。 If and arg-names (parameter name 1, parameter name 2 ...) Together, the usage is args (parameter 1, parameter 2 ...), where the type of parameter 1 and parameter 2 is determined by the parameters of the method represented by Arg-names
Arg-names is used in conjunction with the Proxy method (that is, the method you want to add before or after the proxy method) arg-names (parameter name 1, parameter name 2 ...) where the parameter name 1 parameter name 2 and the proxy method's parameter name is one by one corresponding
The difference between args and arg-names in Spring AOP