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动态代理, ...
随机推荐
- 推文科技:AI解决方案助力内容出海
2017年,推文科技成立,推出业内针对网络文学的AI系统,助推网文批量出海.2018年,阿里云上线海外可用区,推文科技开始与阿里云合作. 创业宣言 创业是一件用行动去实践相信的事情,也许有一天,我 ...
- Serverless 工程实践 | 细数 Serverless 的配套服务
简介: 上文说到云计算的十余年发展让整个互联网行业发生了翻天覆地的变化,Serverless 作为云计算的产物,或者说是云计算在某个时代的表现,被很多人认为是真正意义上的云计算,关于"Se ...
- [Go] 让 go build 生成的可执行文件对 Mac、linux、Windows 平台一致
要做到这一点,使用的是交叉编译选项. CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=windows ...
- Istio微服务入门---通过istio部署微服务实现灰度发布(15)
一.Istio简介 1.1 Istio介绍 官方文档:https://istio.io/docs/concepts/what-is-istio/ 中文官方文档:https://istio.io/zh/ ...
- 如何实现surging 多语言混合微服务异构
1. 背景 作为微服务体系, 应该是不限语言的, 不管是.net.java, 都可以是一个微服务. 可以使用JAVA或者.NET 去实现业务模块,通过统一的消息模型进行传输调用因客户技术栈以多语言,多 ...
- 【简说Python WEB】用户身份验证--Werkzeug
目录 [简说Python WEB]用户身份验证--Werkzeug Flask的security扩展 使用Werkzeug生成密码散列值 系统环境:Ubuntu 18.04.1 LTS Python使 ...
- Typora+免费图床,构建随处可用的Markdown文档
Typora+PicGo+Gitee自动上传图片 视频教程: https://www.bilibili.com/video/BV1hT4y1f7Mf?from=search&seid=1546 ...
- leaflet 河流颜色渐变效果
1.Leaflet-polycolor github地址:https://github.com/Oliv/leaflet-polycolor 插件缺陷:需要把每个折点的颜色都指定才行,一般做不到 2. ...
- C 语言编程 — 指令行参数
目录 文章目录 目录 前文列表 命令行参数 前文列表 <程序编译流程与 GCC 编译器> <C 语言编程 - 基本语法> <C 语言编程 - 基本数据类型> < ...
- 继承与ER图
会员是用户吗? 实体与集合 er图叫实体联系图.什么是实体?是现实中存在的事物个体,用户背后是实际存在的单个人. 对象->实体 类->实体的集合 er图描述的是实体间的联系 会员是真实存在 ...