Spring AOP 中@Pointcut的用法(多个Pointcut)
Spring AOP 中@Pointcut的用法(多个Pointcut)
/**
swagger切面,分开来写
**/
@Aspect
@Component
public class ApiOperationLogAspect {
private Logger logger = LoggerFactory.getLogger(this.getClass()); @Pointcut("@annotation(io.swagger.annotations.ApiOperation)")
public void pointcut() {
} @Around("pointcut()")
public Object around(ProceedingJoinPoint point) { }
}
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface FunctionLog {
String value() default "";
} /**
自定义切面,分开来写
**/
@Aspect
@Component
public class FunctionLogAspect {
private Logger logger = LoggerFactory.getLogger(this.getClass()); @Pointcut("@annotation(com.mytest.insure.annotation.FunctionLog)")
public void pointcut() {
} @Around("pointcut()")
public Object around(ProceedingJoinPoint point) { }
}
Spring Boot AOP @Pointcut拦截注解的表达式与运算符
拦截注解的表达式有3种:@annotation、@within、@target
1、@annotation
匹配有指定注解的方法(注解作用在方法上面)
2、@within
匹配包含某个注解的类(注解作用在类上面)
3、@target
匹配目标对象有指定注解的类(注解作用在类上面)
@target 和@within的区别:
1、@target(注解A):判断被调用的目标对象中是否声明了注解A,如果有,会被拦截;
2、@within(注解A): 判断被调用的方法所属的类中是否声明了注解A,如果有,会被拦截;
3、@target关注的是被调用的对象,@within关注的是调用的方法所在的类;
@PointCut中的运算符
PointCut中可以使用&&、||、! 运算符
同时匹配方法上的和类上的注解
@Pointcut("@annotation(com.test.aop.demo.MyAnnotation) || @within(com.test.aop.demo.MyAnnotation)")
public void cutController(){
}
或者
@Pointcut("@annotation(com.test.aop.demo.MyAnnotation)")
public void cutController(){
}
@Pointcut("@within(com.test.aop.demo.MyAnnotation)")
public void cutService(){
}
@Pointcut("cutController() || cutService()")
public void cutAll(){
}
Spring AOP 中@Pointcut的用法(多个Pointcut)的更多相关文章
- Spring AOP中JoinPoint的用法
Spring JoinPoint的用法 JoinPoint 对象 JoinPoint对象封装了SpringAop中切面方法的信息,在切面方法中添加JoinPoint参数,就可以获取到封装了该方法信息的 ...
- Spring AOP 中@Pointcut的用法
Spring Aop中@pointCut的用法,格式:execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? nam ...
- Spring AOP中定义切点(PointCut)和通知(Advice)
如果你还不熟悉AOP,请先看AOP基本原理,本文的例子也沿用了AOP基本原理中的例子.切点表达式 切点的功能是指出切面的通知应该从哪里织入应用的执行流.切面只能织入公共方法.在Spring AOP中, ...
- spring aop中pointcut表达式完整版
spring aop中pointcut表达式完整版 本文主要介绍spring aop中9种切入点表达式的写法 execute within this target args @target @with ...
- 正确理解Spring AOP中的Around advice
Spring AOP中,有Before advice和After advice,这两个advice从字面上就可以很容易理解,但是Around advice就有点麻烦了. 乍一看好像是Before ad ...
- Spring AOP中的动态代理
0 前言 1 动态代理 1.1 JDK动态代理 1.2 CGLIB动态代理 1.2.1 CGLIB的代理用法 1.2.2 CGLIB的过滤功能 2 Spring AOP中的动态代理机制 2.1 ...
- Spring AOP高级——源码实现(2)Spring AOP中通知器(Advisor)与切面(Aspect)
本文例子完整源码地址:https://github.com/yu-linfeng/BlogRepositories/tree/master/repositories/Spring%20AOP%E9%A ...
- 转:Spring AOP中的动态代理
原文链接:Spring AOP中的动态代理 0 前言 1 动态代理 1.1 JDK动态代理 1.2 CGLIB动态代理 1.2.1 CGLIB的代理用法 1.2.2 CGLIB的过滤功能 2 S ...
- Spring AOP中使用@Aspect注解 面向切面实现日志横切功能详解
引言: AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是软件开发中的一 ...
- Spring AOP中的JDK和CGLib动态代理哪个效率更高?
一.背景 今天有小伙伴面试的时候被问到:Spring AOP中JDK 和 CGLib动态代理哪个效率更高? 二.基本概念 首先,我们知道Spring AOP的底层实现有两种方式:一种是JDK动态代理, ...
随机推荐
- Apache Flink在 bilibili 的多元化探索与实践
简介: bilibili 万亿级传输分发架构的落地,以及 AI 领域如何基于 Flink 打造一套完善的预处理实时 Pipeline. 本文由 bilibili 大数据实时平台负责人郑志升分享,本次分 ...
- [FAQ] golang-migrate/migrate error: migration failed in line 0: (details: Error 1065: Query was empty)
当我们使用 migrate create 创建了迁移文件. 没有及时填写内容,此时运行 migrate 的后续命令比如 up.down 会抛出错误: error: migration failed i ...
- UWP 从文件 StorageFile 转 SoftwareBitmap 图片方法
本文告诉大家如何在 UWP 从 文件 StorageFile 转 SoftwareBitmap 图片的方法 使用以下三步即可从文件 StorageFile 转 SoftwareBitmap 图片 第一 ...
- 通过 KoP 将 Kafka 应用迁移到 Pulsar
通过 KoP 将 Kafka 应用迁移到 Pulsar 版权声明:原文出自 https://github.com/streamnative/kop ,由 Redisant 进行整理和翻译 目录 通过 ...
- Prometheus+Grafana+alertmanager构建企业级监控系统(三)
七.Prometheus监控扩展 7.1 Promethues 采集tomcat监控数据 tomcat_exporter地址:https://github.com/nlighten/tomcat_ex ...
- 一款基于Vue3实现的漂亮且功能强大的在线海报设计器
大家好,我是 Java陈序员. 我们在工作中经常需要设计各种各样的图片,海报.产品图.文章图片.视频/公众号等. 我们可以选择使用 PS 来设计图片,但是有时候想快速完成任务,有没有一款工具支持快速生 ...
- ffmpeg7.0常用命令笔记 windows下
1.多媒体格式转换 ffmpeg -i input.mov -acodec copy -vcodec copy out.mp4 2.从多媒体文件中抽取音频 ffmpeg -i input.mov -v ...
- 基于 RedHat 系的 Linux 常用命令 & 常见系统设定
闲言碎语 除特定指明外,本文默认基于 RedHat Enterprise Linux 8+ 的阐述. 基于CentOS推出的开源系统,国内的阿里推出Anolis OS,华为的OpenEuler.为填补 ...
- Centos7 忘记密码的解决方法
ilo远程修改 重启服务器,点击cold boot 按钮. 开机后,进入内核上按"e",进入编辑模式 在linux删除linux16这一行的地方,写入如下语句,在*.img行之前. ...
- jemeter中json提取器
1.A接口中的单个参数提取,之后用于其他接口 a. 在需要提取字段的接口上右击添加----后置处理器-----json extractor b. 填写json提取器的数据 1.名称:随便填写,方便自己 ...