注解形式的通知

package com.zhujie;

import java.lang.management.GarbageCollectorMXBean;

import org.aopalliance.intercept.Invocation;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;
0
@Component("jj") //注解
@Aspect //声明通知类
public class zhujietongzhi  {
	@Before("execution(public * addstudent(..))")
	public void mybefore(JoinPoint jp) {
		System.out.println("注解形式前置通知");
		System.out.println(jp.getTarget()+"\n"+jp.getArgs().length+"\n");
	}
	
	@AfterReturning(pointcut="execution(public * addstudent(..))",returning="returnvalue")
	public void myafter(JoinPoint jp ,Object returnvalue/*方法没有返回值则不用*/) {
		System.out.println("注解形式后置通知");
		System.out.print(jp.getThis());
	}
	
	@AfterThrowing(pointcut="execution(public * addstudent(..))",throwing="e")
	public void myexception(JoinPoint jp ,IndexOutOfBoundsException e) {
		System.out.println("注解形式的异常通知");
		System.out.println(e.getMessage());
	}
	
	@Around("execution(public * addstudent(..))")
	public void myaround(ProceedingJoinPoint pjp) {
		try {
			System.out.println("beforex");
			pjp.proceed();
			System.out.println("endx");
		} catch (Exception e) {
			// TODO Auto-generated catch block

			System.out.println("error1x");
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			System.out.println("error1x");
		}finally {
			System.out.println("end-advice");
		}
	}
}

  

转载于:https://www.cnblogs.com/qinyios/p/11064088.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值