spring: @Pointcut给重复的注解/切点定义表达式

代码如下:

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");
	}
}

  

2.Pointcut

 org.aspectj.lang.annotation.Pointcut;

 1 package ch2.test;
 2 
 3 import org.aspectj.lang.annotation.AfterReturning;
 4 import org.aspectj.lang.annotation.AfterThrowing;
 5 import org.aspectj.lang.annotation.Aspect;
 6 import org.aspectj.lang.annotation.Before;
 7 import org.aspectj.lang.annotation.Pointcut;
 8 
 9 @Aspect
10 public class Audience2 {
11 
12     
13     //定义命名的切点
14     @Pointcut("execution(** ch2.test.Performance.perform(..))")
15     public void Performance(){}
16     
17     //表演开始之前:关闭手机
18     @Before("Performance()")
19     public void silenCellPhones()
20     {
21         System.out.println("silen cell phones");
22     }
23     
24     //表演开始之前:入座
25     @Before("Performance()")
26     public void takingSeats()
27     {
28         System.out.println("take seats");
29     }
30     
31     //表演开始之后:鼓掌
32     @AfterReturning("Performance()")
33     public void applause()
34     {
35         System.out.println("clap clap clap");
36     }
37     
38     //表演结束之后:表演失败退票
39     @AfterThrowing("Performance()")
40     public void demandRefund()
41     {
42         System.out.println("demand refund");
43     }
44     
45 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值