pointcut 案例配置

package cn.itcast.spring.aop.aspectj;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareParents;
import org.aspectj.lang.annotation.Pointcut;

/**
 * 观众
 */
@Aspect
public class Audience {
	
	/**
	 * 引入通知,
	 */
	@DeclareParents(value="cn.itcast.spring.aop.aspectj.Singer",defaultImpl=ModifyDateImpl.class)
	private ModifyDate md ;
	/**
	 * 定义在切入点
	 */
	@Pointcut("execution(* cn.itcast.spring.aop.aspectj.Performer.*(..))")
	public void perform(){
	}
	/**
	 * 坐好
	 */
	@Before(value="perform()")
	public void takeSeat(){
		System.out.println("takeSeat");
	}
	
	/**
	 * 关机
	 */
	@Before(value="perform()")
	public void turnOffCellphone(JoinPoint jp){
		System.out.println(jp.getSignature().getName());
		System.out.println(jp.getArgs());
		System.out.println(jp.getTarget());
		System.out.println(jp.getThis());
		System.out.println("turnOffCellphone");
	}
	
	/**
	 * returning:指定哪个参数接受方法的返回值
	 */
	@AfterReturning(pointcut="perform()",returning="ret")
	public void applaud(Object ret){
		System.out.println("applaud");
		System.out.println("ret = " + ret);
	}
	
	/**
	 * 退票
	 * throwing:指定哪个参数接受异常信息
	 */
	@AfterThrowing(pointcut="perform()",throwing="e")
	public void demandMoney(Exception e){
		System.out.println("demandMoney");
		System.out.println("出事了 " + e.getMessage());
	}
	
	@After("perform()")
	public void goHome(){
		System.out.println("goHome");
	}
}

你可能感兴趣的:(pointcut 案例配置)