@Pointcut的用法
在Spring 2.0中,Pointcut的定义包括两个部分:Pointcut表示式(expression)和Pointcut签名(signature)。让我们先看看execution表示式的格式:
在各个pattern中可以使用“*”来表示匹配所有。在(param-pattern)中,可以指定具体的参数类型,多个参数间用“,”隔开,各个也可以用“*”来表示匹配任意类型的参数,如(String)表示匹配一个String参数的方法;(*,String)表示匹配有两个参数的方法,第一个参数可以是任意类型,而第二个参数是String类型;可以用(..)表示零个或多个任意参数。
现在来看看几个例子:
1)execution(* *(..))
表示匹配所有方法
2)execution(public * com. savage.service.UserService.*(..))
表示匹配com.savage.server.UserService中所有的公有方法
3)execution(* com.savage.server..*.*(..))
表示匹配com.savage.server包及其子包下的所有方法
除了execution表示式外,还有within、this、target、args等Pointcut表示式。一个Pointcut定义由Pointcut表示式和Pointcut签名组成,例如:
- execution(modifier-pattern?
- ret-type-pattern
- declaring-type-pattern?
- name-pattern(param-pattern)
- throws-pattern?)

- //Pointcut表示式
- @Pointcut("execution(* com.savage.aop.MessageSender.*(..))")
- //Point签名
- private void log(){} 然后要使用所定义的Pointcut时,可以指定Pointcut签名,如
上面的定义等同与:

- @Before("og()")

- @Before("execution(* com.savage.aop.MessageSender.*(..))")

Pointcut定义时,还可以使用&&、||、!
- @Pointcut("execution(* com.savage.aop.MessageSender.*(..))")
- private void logSender(){}
- @Pointcut("execution(* com.savage.aop.MessageReceiver.*(..))")
- private void logReceiver(){}
- @Pointcut("logSender() || logReceiver()")
- private void logMessage(){}

这个例子中,logMessage()将匹配任何MessageSender和MessageReceiver中的任何方法。
还可以将一些公用的Pointcut
- package com.savage.aop;
- import org.aspectj.lang.annotation.*;
- public class Pointcuts {
- @Pointcut("execution(* *Message(..))")
- public void logMessage(){}
- @Pointcut("execution(* *Attachment(..))")
- public void logAttachment(){}
- @Pointcut("execution(* *Service.*(..))")
- public void auth(){}
- }

在使用这些Pointcut时,指定完整的类名加上Pointcut
![]() |
@Pointcut的用法的更多相关文章
- Spring AOP 中@Pointcut的用法
Spring Aop中@pointCut的用法,格式:execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? nam ...
- 10.Spring——框架的AOP
1.Spring 框架的 AOP 2.Spring 中基于 AOP 的 XML架构 3.Spring 中基于 AOP 的 @AspectJ 1.Spring 框架的 AOP Spring 框架的一个关 ...
- AOP 面向切面 记录请求接口的日志
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是软件开发中的一个热点, ...
- spring事务以及springweb
什么是事务.事务特性.事务隔离级别.spring事务传播特性 https://www.cnblogs.com/zhangqian1031/p/6542037.html Spring AOP 中@Poi ...
- 【SpringBoot】SpingBoot整合AOP
https://blog.csdn.net/lmb55/article/details/82470388 [SpringBoot]SpingBoot整合AOPhttps://blog.csdn.net ...
- AOP切面详解
一.spring-aop.xml文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns= ...
- 【spring AOP】@Pointcut的12种用法
@Pointcut用来标注在方法上来定义切入点. 使用格式:@ 注解(value="表达标签 (表达式格式)").如:@Pointcut("execution(* com ...
- 切面AOP的切点@Pointcut用法
格式: execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern ...
- 深入分析@Transactional的用法
关键词:事务, 编程式事务,声明式事务.spring 事务管理.AOP事务增强.@Transactional 在分析深入分析@Transactional的使用之前,我们先回顾一下事务的一些基本内容. ...
随机推荐
- Linux : Vim 使用与配置 (附 GitHub 自动化配置脚本)
由于经常使用 vim 编辑配置文件,有时候也会进行使用vim 编写一些脚本和c/c++ 程序,所以配置一个常用的 vim 是很是必要的.这篇博文主要是记录vim使用和配置相关的一些知识点. 关于vim ...
- 联想笔记本Y7000P安装nvidia,cuda,tensorflow,pytorch
Y7000P电脑环境i7处理器,1060显卡,16g内存,win10家庭版(系统版本号1809),在联想官网升级过bios,所有驱动都是最新.(截止时间点2019年3月1日) python3.5 安装 ...
- NGINX 安装于配置
just a simple example, for more information -> http://nginx.org/en/docs/.1.vi /etc/yum.repos.d/ng ...
- 环境变量(environment variable)
环境变量是什么 环境变量指的就是操作系统当中的一些变量.可以通过修改环境变量,来对计算机进行配置(主要是来配置一些路径的) 查看环境变量右键 计算机(此电脑),选择属性——系统界面左侧选择 高级系统设 ...
- RelativeLayout 总结
1)参考元素获取:id: 2)位置关系设置: 3)对齐关系设置:
- 洛谷 P1032 字串变换
题目描述 已知有两个字串 A, B 及一组字串变换的规则(至多6个规则): A1 -> B1 A2 -> B2 规则的含义为:在 A$中的子串 A1 可以变换为 B1.A2 可以变换为 B ...
- Idea设置快捷键以及修改Eclipse的debug快捷键
Idea强大不多说了,用久了都可以习惯,但是感觉Idea的debug真是不如eclipse好用,Idea的快捷键都是组合键,用着繁琐.两种方法可以设置eclipse的快捷键: 1:直接全局都使用ecl ...
- nginx和php-fpm调用方式
一.背景: 在开发中碰到一个问题,项目以nginx+php-fpm形式访问交互,结果访问项目时报错如下图: 二.分析: 提示很明确嘛,去看error.log(在nginx.conf或者vhost里 ...
- Mysql数据库的加密与解密
数据加密.解密在安全领域非常重要.对程序员而言,在数据库中以密文方式存储用户密码对入侵者剽窃用户隐私意义重大. 有多种前端加密算法可用于数据加密.解密,下面我向您推荐一种简单的数据库级别的数据加密.解 ...
- VsCode插件开发之入门示例
主要参考官网:https://code.visualstudio.com/api/get-started/your-first-extension 其实也就三步 一.安装环境 npm install ...