代码如下:
package ch2.test; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Aspect; @Aspect public class Audience { //表演之前:观点手机 @Before("execution(** ch2.test.Performance.perform(..))") public void silenceCellPhones() { System.out.println("silenCellPhones"); } //表演之前:就座 @Before("execution(** ch2.test.Performance.perform(..))") public void takingSeats() { System.out.println("take seats"); } //表演之后:鼓掌 @AfterReturning("excuttion(** ch2.test.Performance.perform(..))") public void applause() { System.out.println("clap clap clap !!!"); } //表演失败:退票 @AfterThrowing("execution(** ch2.test.Performance.perform(..))") public void demandRefund() { System.out.println("demanding a refund"); } }