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动态代理, ...
随机推荐
- Spring Boot 微服务性能下降九成!使用 Arthas 定位根因
简介: 接收到公司业务部门的开发反馈,应用在升级公司内部框架后,UAT(预生产)环境接口性能压测不达标. 背景 接收到公司业务部门的开发反馈,应用在升级公司内部框架后,UAT(预生产)环境接口性能压测 ...
- 数据改变后更新UI(SetProperty/RaiseCanExecuteChanged)
View代码 1 <StackPanel> 2 <TextBlock Text="方法一"></TextBlock> 3 <TextBox ...
- SQL server 批量删除表
select 'drop table '+name+';' from sys.tables declare c cursor forselect NAME from sysobjects where ...
- 4.k8s-配置网络策略 NetworkPolicy
一.基本了解 官方文档:https://kubernetes.io/zh-cn/docs/concepts/services-networking/network-policies/基本了解: 1.网 ...
- STM32【HAL库】使用外部SRAM程序
#include <board.h> #ifdef BSP_USING_SRAM #include <drv_common.h> #include <rtthread.h ...
- 我用 GitHub 9.8k 的 Go 语言 2D 游戏引擎写了个游戏
前言 hi,大家好,这里是白泽.今天给大家分享一个 GitHub 9.8k 的 Go 语言 2D 游戏引擎. https://github.com/hajimehoshi/ebiten 引擎的贡献者依 ...
- linux服务器配置查看
查看linux服务器配置 查硬盘信息 sblk 看sda sdb sdc之类的 以下可以看出是500G sda第一块,sdb是第二块 以下可以看出是 1T+100G 查内存 free -h 查cpu ...
- Threading Programming Guide:One
苹果支持的产生线程的方式 Operation Object 使用OperationQueue,具体可以参考:Concurrency Programming Guide GCD 使用诸如dispatch ...
- WEB服务与NGINX(2)-NGINX的I/O模型
WEB服务与NGINX(2)-NGINX的I/O模型 目录 WEB服务与NGINX(2)-NGINX的I/O模型 1. linux I/0模型及在NGINX中的应用 1.1 I/O模型概述 1.2 系 ...
- Ubuntu实现与主机Windows复制粘贴(安装VMware Tools)
若不能实现主机与客户机间粘贴复制执行以下命令 sudo apt-get autoremove open-vm-tools sudo apt-get install open-vm-tools sudo ...