2019独角兽企业重金招聘Python工程师标准>>>

8.2.3 Declaring a pointcut

Recall that pointcuts determine join points of interest, and thus enable us to control when advice executes. Spring AOP only supports method execution join points for Spring beans, so you can think of a pointcut as matching the execution of methods on Spring beans.

A pointcut declaration has two parts: a signature comprising a name and any parameters, and a pointcut expression that determines exactly which method executions we are interested in.

Spring AOP 仅仅支持Bean里面的方法切入点,所以切入点主要作用就是申明匹配Bean里面的方法。Pointcut 申明有两个部分哦,一个是签名方法 包含有方法名字和参数。另外一个是切入点表达式,这个是用来申明在哪些方法上面执行切入。例如:

@Pointcut("execution(* com.yuan.service..ad*(..))")

public void daddff(){};

/***

In the @AspectJ annotation-style of AOP, a pointcut signature is provided by a regular method definition, and the pointcut expression is indicated using the @Pointcut annotation (the method serving as the pointcut signature must have a void return type).

pointcut 签名 必须是无返回值得。

下面就是一个例子:

An example will help make this distinction between a pointcut signature and a pointcut expression clear. The following example defines a pointcut named'anyOldTransfer' that will match the execution of any method named 'transfer':

@Pointcut("execution(* transfer(..))")// the pointcut expression
private void anyOldTransfer() {}     // the pointcut signature

The pointcut expression that forms the value of the @Pointcut annotation is a regular AspectJ 5 pointcut expression. For a full discussion of AspectJ’s pointcut language, see the AspectJ Programming Guide (and for extensions, the AspectJ 5 Developers Notebook) or one of the books on AspectJ such as "Eclipse AspectJ" by Colyer et. al. or "AspectJ in Action" by Ramnivas Laddad.

注意:pointcut expression

Spring AOP users are likely to use the execution pointcut designator the most often. The format of an execution expression is:

execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)            throws-pattern?)

All parts except the returning type pattern (ret-type-pattern in the snippet above), name pattern, and parameters pattern are optional. The returning type pattern determines what the return type of the method must be in order for a join point to be matched. Most frequently you will use * as the returning type pattern, which matches any return type. A fully-qualified type name will match only when the method returns the given type. The name pattern matches the method name. You can use the * wildcard as all or part of a name pattern. The parameters pattern is slightly more complex: () matches a method that takes no parameters, whereas (..)matches any number of parameters (zero or more). The pattern (*) matches a method taking one parameter of any type, (*,String) matches a method taking two parameters, the first can be of any type, the second must be a String. Consult the Language Semantics section of the AspectJ Programming Guide for more information.

Some examples of common pointcut expressions are given below.

转载于:https://my.oschina.net/u/2308739/blog/397246

spring aop 申明了切面类之后,如何申明切入点呢?相关推荐

  1. spring aop如何在切面类中获取切入点相关方法的参数、方法名、返回值、异常等信息

    aop思想可以很好的帮助我们实现代码的解耦,比如我们之前提到的,将日志代码与业务层代码完全独立,通过spring aop的代理类进行整合.在切面类中,我们也能够通过spring提供的接口,很好的获取原 ...

  2. 【JavaEE】Spring AOP (面向切面)详解

    目录: 1. 什么是 Spring AOP? 1.1 AOP 1.2 使用 AOP 的场景 2. AOP 组成 2.1 切面(Aspect) 2.2 连接点(Join Point) 2.3 切点(Po ...

  3. Spring AOP动态代理-切面

    2019独角兽企业重金招聘Python工程师标准>>> 在上一节中,我们通过Advice可以对目标类进行增强,使得目标类在调用的时候可以执行增强类中的代码,但是,增强类适配了目标类中 ...

  4. 使用 HSDB 查看Spring AOP产生的代理类

    场景:Spring在运行期间,会自动给咱们的业务类Service Bean等等生成,出于好奇,想康康Spring到底给咱们生成了什么东西,这时候可以使用 HSDB 工具进行查看. 首先确保本机安装了J ...

  5. Spring注解方式配置切面类

  6. Spring AOP切点表达式详解

    1. 简介 面向对象编程,也称为OOP(即Object Oriented Programming)最大的优点在于能够将业务模块进行封装,从而达到功能复用的目的.通过面向对象编程,不同的模板可以相互组装 ...

  7. Spring AOP(通知、连接点、切点、切面)

    一.AOP术语 通知(Advice)   切面的工作被称为通知.通知定义了切面是什么以及何时使用.除了描述切面要完成的工作,通知还解决了何时执行这个工作的问题. 5种通知类型: 前置通知(Before ...

  8. Spring AOP(面向切面编程)

    AOP(Aspect Oriented Programming),也就是面向切面编程,作为面向对象编程的一种补充,AOP已经成为一种比较成熟的编程方式.可以这样理解:OOP是从静态角度考虑程序结构,而 ...

  9. JavaEE——Spring AOP(面向切面编程)

    目录 1.面向切面编程(AOP) 2.AOP术语 3.AOP类型 4.AOP 的优势 5.Spring AOP 的代理机制 6.Spring AOP 连接点 7.Spring AOP 通知类型 8.基 ...

最新文章

  1. 七月工作笔记 7.7 - 7.11
  2. 【Linux】linux下查看目录所在分区
  3. EnvironmentError: mysql_config not found
  4. 用C#来开发CAD插件,含源代码
  5. 前端面试常考的10大排序算法
  6. [转载] QT中的connect用法总结
  7. 电源大师课笔记 2.7
  8. STM32 JLINK接口定义 JTAG/SWD
  9. FPGA深度学习加速(1) - Xilinx ug892-Vivado design flows overview (Vivado设计流程简述) - 阅读笔记
  10. 【升级到Java 17】switch 表达式
  11. vue项目目录详细解读
  12. Stefan - 人生目前学到的21样事
  13. A. Groundhog and 2-Power Representation (递归 高精度) 2020牛客暑期多校训练营(第九场)
  14. win10热点 ip配置失败
  15. Android:InflateException: Binary XML file line #12: Error inflating class null
  16. 快速集成腾讯云短信实现短信发送(Spring Boot)
  17. 微信小程序自定义模态框
  18. 云米发布上市后首份财报:非GAAP净利3875万 同比增36%
  19. python读取Excel表格文件
  20. LayIM 3.9.1与ASP.NET SignalR实现Web聊天室快速入门(四)之ASP.NET SignalR核心功能介绍

热门文章

  1. linux下忘记mysql root密码
  2. 运用Smark.SocketAsyncs方便实现数据交互服务
  3. 零基础学JAVA]Java SE基础部分-01. Java发展及JDK配置
  4. 低版本IE浏览器不支持前端代码修改属性remove()的解决办法
  5. Access数据库审计工具mdbtools
  6. 配置JDKAndroid 2D游戏引擎AndEngine
  7. android surfaceview动画,怎么让android的surfaceview中的动画更加平滑流畅
  8. HoloLens再添一应用领域!Microsoft和Trimble联手开启设施管理新篇章!
  9. [unreal4入门系列之十] UE4添加角色到场景中
  10. 家用计算机先驱逝世:Linux之父曾受他启发,马斯克悼念