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)的更多相关文章

  1. Spring AOP中JoinPoint的用法

    Spring JoinPoint的用法 JoinPoint 对象 JoinPoint对象封装了SpringAop中切面方法的信息,在切面方法中添加JoinPoint参数,就可以获取到封装了该方法信息的 ...

  2. Spring AOP 中@Pointcut的用法

    Spring Aop中@pointCut的用法,格式:execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? nam ...

  3. Spring AOP中定义切点(PointCut)和通知(Advice)

    如果你还不熟悉AOP,请先看AOP基本原理,本文的例子也沿用了AOP基本原理中的例子.切点表达式 切点的功能是指出切面的通知应该从哪里织入应用的执行流.切面只能织入公共方法.在Spring AOP中, ...

  4. spring aop中pointcut表达式完整版

    spring aop中pointcut表达式完整版 本文主要介绍spring aop中9种切入点表达式的写法 execute within this target args @target @with ...

  5. 正确理解Spring AOP中的Around advice

    Spring AOP中,有Before advice和After advice,这两个advice从字面上就可以很容易理解,但是Around advice就有点麻烦了. 乍一看好像是Before ad ...

  6. Spring AOP中的动态代理

    0  前言 1  动态代理 1.1 JDK动态代理 1.2 CGLIB动态代理 1.2.1 CGLIB的代理用法 1.2.2 CGLIB的过滤功能 2  Spring AOP中的动态代理机制 2.1  ...

  7. Spring AOP高级——源码实现(2)Spring AOP中通知器(Advisor)与切面(Aspect)

    本文例子完整源码地址:https://github.com/yu-linfeng/BlogRepositories/tree/master/repositories/Spring%20AOP%E9%A ...

  8. 转:Spring AOP中的动态代理

    原文链接:Spring AOP中的动态代理 0  前言 1  动态代理 1.1 JDK动态代理 1.2 CGLIB动态代理 1.2.1 CGLIB的代理用法 1.2.2 CGLIB的过滤功能 2  S ...

  9. Spring AOP中使用@Aspect注解 面向切面实现日志横切功能详解

    引言: AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是软件开发中的一 ...

  10. Spring AOP中的JDK和CGLib动态代理哪个效率更高?

    一.背景 今天有小伙伴面试的时候被问到:Spring AOP中JDK 和 CGLib动态代理哪个效率更高? 二.基本概念 首先,我们知道Spring AOP的底层实现有两种方式:一种是JDK动态代理, ...

随机推荐

  1. 阿里巴巴云原生大数据运维平台 SREWorks 正式开源

    ​简介:阿里巴巴云原生大数据运维平台 SREWorks,沉淀了团队近10年经过内部业务锤炼的 SRE 工程实践,今天正式对外开源,秉承"数据化.智能化"运维思想,帮助运维行业更多的 ...

  2. 如何快速调度 PTS 的百万并发能力

    ​简介:压测是通过模拟用户行为对业务系统发起请求,测算出系统的承载能力,并对系统做一次全面的体检,压测后可根据压测表现优化系统瓶颈,防止出现线上故障. 作者:灵苒 在实际的业务场景中,压测是必不可少的 ...

  3. 编译优化 | LLVM代码生成技术详解及在数据库中的应用

    简介: 作者:长别 1. 前言 随着IT基础设施的发展,现代的数据处理系统需要处理更多的数据.支持更为复杂的算法.数据量的增长和算法的复杂化,为数据分析系统带来了严峻的性能挑战.近年来,我们可以在数据 ...

  4. 内含干货PPT下载|一站式数据管理DMS及最新解决方案发布

    ​简介: 今天主要给大家介绍一站式数据管理平台DMS以及解决方案的发布.议题包含企业数据管理当前的一些痛,DMS一站式数据管理平台以及其核心技术,实时数仓解决方案以及相应的应用实践. "数聚 ...

  5. STLINK/V2下载器接线方法

    一.ST-LINK ST-LINK产品如下图所示: ST-LINK接口定义如下图所示 ST-LINK与stm32接线 使用SW接法只需要四根线: STM32 ST-LINK VCC(3.3V) TVC ...

  6. js原型,原型链(不断补充中)

    1.如何使用构造器? function Person(name, age) { this.name = name; this.age = age; } var man = new Person(&qu ...

  7. 深入学习和理解Django模板层:构建动态页面

    title: 深入学习和理解Django模板层:构建动态页面 date: 2024/5/5 20:53:51 updated: 2024/5/5 20:53:51 categories: 后端开发 t ...

  8. 02、Linux 排查

    Linux 分析排查 1.敏感文件信息 1.1.tmp 目录 /tmp:临时目录文件,每个用户都可以对它进行读写操作.因此一个普通用户可以对 /tmp 目录执行读写操作(ls -alt) 筛查 /tm ...

  9. 15、数据库加固-redis 加固

    1.禁止网络访问 Redis 服务 更改配置文件,使服务监听本地回环地址 修改 redis 配置文件:vi 安装路径/redis.conf 确保:bind 127.0.0.1(::1:表示 ipv6 ...

  10. vue子组件给父组件传值

    子组件: <template> <div class="app"> <input @click="sendMsg" type=&q ...