书接上回
上回降到LEO把before和after重构,改为使用around。
日本人提高了防范,LEO不确定需要从哪个方法入手,需要一些通配符来侵入方法。
这里我们就谈谈AOP语法中表达式
@Pointcut("execution(public void com.spring.service.Person.haveSleep())")
这是之前例子的表达式。我们来详细讲解一下
这是指定了一个具体的方法,这个很好理解。
1、假设Person类中haveSleep()方法有一个重载方法
public void haveSleep(date starttime ,date endtime)
这两个方法LEO都需要编制waving,怎么办,我们把这个切入点改为
@Pointcut("execution(public void com.spring.service.Person.haveSleep(..))")
加了2个.问题就解决了。有点类似于正则表达式吧。
2、LEO还需要编织其他睡觉的方法,包括haveNap()和haveNightmare()方法,LEO发现所有睡觉的方法都是以have开头的。怎么办呢?
@Pointcut("execution(public void com.spring.service.Person.have*(..))")
同正则表达式一样*表示任意数字的字符
3、LEO需要把范围再扩大一些,扩大到com.spring.service下所有类的所有方法
@Pointcut("execution(* com.spring.service.*.*(..))")
星号的用法自己摸索和体会一下吧。
4、之前在谈过使用@AfterThrowing来捕获异常,使用表达式可以专门针对Throws的方法进行编织waving。(即方法声明中带有Throws的方法)
@Pointcut("execution(public void com.spring.service.Person.have*() throws Exception)"
在这里我们以have开头的方法有多个,但是只会在
public void haveNightmare()throws Exception方法上进行编织
先到这里啦,一般的需求,这几种相互组合就差不多了,再有需要看文档即可
分享到:
相关推荐
NULL 博文链接:https://garrincha.iteye.com/blog/2112027
NULL 博文链接:https://garrincha.iteye.com/blog/2111779
NULL 博文链接:https://garrincha.iteye.com/blog/2111957
详细介绍spring aop中9种切入点表达式的写法execute、within、this、target、args、@target、@within、@annotation、@args
使用mindmaster打开
死磕Spring之AOP篇 - Spring AOP两种代理对象的拦截处理(csdn)————程序
SpringBoot下的Spring——DAY04——动态代理总结、AOP、自定义注解进行拦截、动态获取注解参数、通知方法 1.动态代理总结 1.1 JDK动态代理特点 1.2 CGlib动态代理 1.2.1 CGLib特点说明 1.3 动态代理的作用 2 Spring...
在Spring AOP中关注点(concern)和横切关注点(cross-cutting concern)有什么不同? AOP有哪些可用的实现? Spring中有哪些不同的通知类型(advice types)? Spring AOP 代理是什么? 引介(Introduction)是什么? 连接...
spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop
spring aop jar 包
spring-aop-1.1.1.jar spring-aop-1.2.6.jar spring-aop-1.2.9.jar spring-aop-2.0.2.jar spring-aop-2.0.6.jar spring-aop-2.0.7.jar spring-aop-2.0.8.jar spring-aop-2.0.jar spring-aop-2.5.1.jar spring-aop-...
切入点指示符用来指示切入点表达式目的,,在Spring AOP中目前只有执行方法这一个连接点,Spring AOP支持的AspectJ切入点指示符如下: execution:用于匹配方法执行的连接点; within:用于匹配指定类型内的方法执行...
一、适合人群 1、具备一定Java编程基础,初级开发者 2、对springboot,mybatis,mysql有基本认识 3、对spring aop认识模糊的,不清楚如何实现Java 自定义注解的 ...4、spring boot,mybatis,druid,spring aop的使用
基于注解实现SpringAop基于注解实现SpringAop基于注解实现SpringAop
Spring框架的关键组件之一是面向方面编程(AOP)框架。 面向方面的编程需要将程序逻辑分解成不同的部分。 此教程将通过简单实用的方法来学习Spring框架提供的AOP/面向方面编程。
spring aop的demo spring aop的demo
springaop依赖的jar包,spring版本2.5.6,如果需要,可以下载使用,欢迎各位评论指出不足
开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE...
Spring AOP 几个不同使用方法的完整例子,使用Junit4c测试, 在我的博客上有不同配置组合的说明,可以参考