AOP組合可以更加的方便簡潔,但不建議初學者使用,初學嘛,打好基礎更重要!!!
切入點表達式可以使用’&&’,’||’ 和“!”進行組合
package com.yyq.aspectJAdvanced;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class TestAspect {
//與/非
@Before("!target(com.yyq.aspectJAdvanced.NaiveWaiter) && execution(* serveTo(..))")
public void notServeInNaiveWaiter(){
System.out.println("--notServeInNaiveWaiter() executed!--");
}
//與
@After("within(com.yyq.aspectJAdvanced.*) && execution(* greetTo(..))")
public void greetToFun(){
System.out.println("--greetToFun() executed!--");
}
//或
@AfterReturning("target(com.yyq.aspectJAdvanced.Waiter) || target(com.yyq.aspectJAdvanced.Seller)")
public void waiterOrSeller(){
System.out.println("--waiterOrSeller() executed!--");
}
}
也可以通過名稱來引用切入點表達式。
當組合切入點子表達式時,’&&‘在XML文檔中是很不方便,所以可以用關鍵字**‘and’, ‘or’ ,‘not’ 可以分別代替’&&’,’||’ 和’ !’**
<aop:config>
<aop:aspect id="myAspect" ref="aBean">
<aop:pointcut id="businessService"
expression="execution(* com.xyz.myapp.service.*.*(..)) **and** this(service)"/>
<aop:before pointcut-ref="businessService" method="monitor"/>
...
</aop:aspect>
</aop:config>
。
。
xml端的來源於:https://blog.csdn.net/fly910905/article/details/78974724/