spring: @Pointcut给重复的注解/切点定义表达式
2024-10-15 21:37:22
代码如下:
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;
package ch2.test; 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.Pointcut; @Aspect
public class Audience2 { //定义命名的切点
@Pointcut("execution(** ch2.test.Performance.perform(..))")
public void Performance(){} //表演开始之前:关闭手机
@Before("Performance()")
public void silenCellPhones()
{
System.out.println("silen cell phones");
} //表演开始之前:入座
@Before("Performance()")
public void takingSeats()
{
System.out.println("take seats");
} //表演开始之后:鼓掌
@AfterReturning("Performance()")
public void applause()
{
System.out.println("clap clap clap");
} //表演结束之后:表演失败退票
@AfterThrowing("Performance()")
public void demandRefund()
{
System.out.println("demand refund");
} }
最新文章
- [转]Android Binder设计与实现 - 设计篇
- ExtJs 学习之开篇(三)Ext.grid.Panel表格中的处理
- [py]特殊函数+文件保护
- Vi命令:如何删除全部内容?
- 【转】关于URL编码/javascript/js url 编码/url的三个js编码函数
- img标签src=";";和background-image:url();引发两次请求页面bug
- 将String类型的XML解析并设置到实体类中
- DevExpress LookUpEdit和ComboBoxEdit部分用法
- linux_memcached_memcachedb
- golang protobuf
- c语言-函数的定义及传参
- 解密电子书之一:电子墨水(eink)
- Silverlight下的Socket通讯
- Java--回调接口
- LeetCode 381. Insert Delete GetRandom O(1) - Duplicates allowed (插入删除和获得随机数 常数时间 允许重复项)
- JavaScript(第二十五天)【事件绑定及深入】
- TLS 1.3 VS TLS 1.2,让你明白 TLS 1.3 的强大
- WCF系列_WCF如何选择不同的绑定
- pytorch bug
- Gitlab+Jenkins学习之路(十四)之自动化脚本部署实践
热门文章
- getTrim(strMz)-我的JavaScript函数库-mazey.js
- 斯坦福大学Andrew Ng - 机器学习笔记(4) -- 机器学习算法的选择与评估
- 运行scrapy保存图片,报错ValueError: Missing scheme in request url: h
- 修改mysql root的密码
- always on 技术
- Oracle学习笔记—常用函数
- Django of python 中文文档 及debug tool
- centos中搭建nginx环境
- MySQL数据库(8)_MySQL数据库总结
- Python基础(12)_python模块之sys模块、logging模块、序列化json模块、pickle模块、shelve模块