编写watchPerformance()

public void watchPerformance(ProceedingJoinPoint joinpoint) {
		try {
			System.out.println("take seat");
			System.out.println("trun off phone");
			long start = System.currentTimeMillis();
			System.out.println(start);
			
			joinpoint.proceed();
			
			long end = System.currentTimeMillis();
			System.out.println(end);
			System.out.println("applaud");
			System.out.println("spend time:"+(end-start)+"milliseconds");
		} catch (Throwable e) {
			e.printStackTrace();
			System.out.println("refund");
		}
	}

 

配置文件

<aop:config>
	<aop:aspect ref="audience">
		<aop:pointcut expression="execution(* *.perform(..))" id="a"/>
		<aop:around pointcut-ref="a" method="watchPerformance"/>
	</aop:aspect>
</aop:config>

 

运行结果
声明环绕通知
 

相关文章: