The difference between aop:advisor and aop:aspect in spring AOP "love to play cool Java PHP learning path"
Source: Internet
Author: User
In spring's configuration, these two tags are used. So what's the difference?
<bean id= "Testadvice" class= "Com.myspring.app.aop.MyAdvice"/>/Slice code when using <aop:aspect> configuration, if the slice code is automatically injected to be An, then <aop:aspect> ref attributes directly to the bean injected name on it! <aop:config> <aop:aspect ref= "Testadvice" id= "Testaspect" > <aop:pointcut expression= "(E Xecution (* com.myspring.app.aop.testpoint.* (..))) " Id= "Testpointcut"/> <aop:before method= "Dobefore" pointcut-ref= "Testpointcut"/> Ect> </aop:config>
<aop:config> <aop:pointcut expression= "(Execution (* com.myspring.app.aop.testpoint.* (..)))" Id= "MyPoint"/> <aop:advisor advice-ref= "Testadvice" pointcut-ref= "MyPoint"/> </aop:config> Note: 2 The writing order of the format. ========================================================================= package COM.MYSPRING.APP.AOP;
Import Java.lang.reflect.Method;
Import Org.aspectj.lang.JoinPoint; Import Org.springframework.aop.MethodBeforeAdvice;
/** * Method Forward Notification * @author Michael * * * * * * * @Component ("myadvice")//if it is automatic assembly, the public class Myadvice can be written directly in the ref attribute when defining the slice imple ments methodbeforeadvice{//If the Aop:advisor configuration is used, then the slice logic must implement the advice interface! Otherwise it will fail! @Override public void before (method method, object[] args, Object target) throws Throwable {System.out.printl N ("predecessor notice"); }
If it is <aop:aspect> configuration, write a generic method, and then specify the specific method name in the slice configuration! public void Dobefore (Joinpoint point) throws Throwable {
} }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service