`

Spring Aop配置时的切入点表达式

 
阅读更多

Some examples of common pointcut expressions are given below.

  • the execution of any public method:

  • execution(public * *(..))
  • the execution of any method with a name beginning with "set":

  • execution(* set*(..))
  • the execution of any method defined by the AccountService interface:

  • execution(* com.xyz.service.AccountService.*(..))
  • the execution of any method defined in the service package:

  • execution(* com.xyz.service.*.*(..))
  • the execution of any method defined in the service package or a sub-package:

  • execution(* com.xyz.service..*.*(..))
  • any join point (method execution only in Spring AOP) within the service package:

  • within(com.xyz.service.*)
  • any join point (method execution only in Spring AOP) within the service package or a sub-package:

    within(com.xyz.service..*)
  • any join point (method execution only in Spring AOP) where the proxy implements the AccountService interface:

    this(com.xyz.service.AccountService)

     

    'this' is more commonly used in a binding form :- see the following section on advice for how to make the proxy object available in the advice body.

     

     

  • any join point (method execution only in Spring AOP) where the target object implements the AccountService interface:

    target(com.xyz.service.AccountService)

     

    'target' is more commonly used in a binding form :- see the following section on advice for how to make the target object available in the advice body.

     

     

  • any join point (method execution only in Spring AOP) which takes a single parameter, and where the argument passed at runtime is Serializable:

    args(java.io.Serializable)

    'args' is more commonly used in a binding form :- see the following section on advice for how to make the method arguments available in the advice body.

    Note that the pointcut given in this example is different to execution(* *(java.io.Serializable)): the args version matches if the argument passed at runtime is Serializable, the execution version matches if the method signature declares a single parameter of type Serializable.

  • any join point (method execution only in Spring AOP) where the target object has an @Transactional annotation:

    @target(org.springframework.transaction.annotation.Transactional)

     

    '@target' can also be used in a binding form :- see the following section on advice for how to make the annotation object available in the advice body.

     

     

  • any join point (method execution only in Spring AOP) where the declared type of the target object has an @Transactional annotation:

    @within(org.springframework.transaction.annotation.Transactional)

     

    '@within' can also be used in a binding form :- see the following section on advice for how to make the annotation object available in the advice body.

     

     

  • any join point (method execution only in Spring AOP) where the executing method has an @Transactional annotation:

    @annotation(org.springframework.transaction.annotation.Transactional)

     

    '@annotation' can also be used in a binding form :- see the following section on advice for how to make the annotation object available in the advice body.

     

     

  • any join point (method execution only in Spring AOP) which takes a single parameter, and where the runtime type of the argument passed has the @Classified annotation:

    @args(com.xyz.security.Classified)

     

    '@args' can also be used in a binding form :- see the following section on advice for how to make the annotation object(s) available in the advice body.

     

     

  • any join point (method execution only in Spring AOP) on a Spring bean named 'tradeService':

    bean(tradeService)
  • any join point (method execution only in Spring AOP) on Spring beans having names that match the wildcard expression '*Service':

    bean(*Service)

对应的中文:

任意公共方法的执行: 
execution(public * *(..)) 
任何一个以“set”开始的方法的执行: 
execution(* set*(..)) 
AccountService 接口的任意方法的执行: 
execution(* com.xyz.service.AccountService.*(..)) 
定义在service包里的任意方法的执行: 
execution(* com.xyz.service.*.*(..)) 
定义在service包或者子包里的任意方法的执行: 
execution(* com.xyz.service..*.*(..)) 
在service包里的任意连接点(在Spring AOP中只是方法执行) : 
within(com.xyz.service.*) 
在service包或者子包里的任意连接点(在Spring AOP中只是方法执行) : 
within(com.xyz.service..*) 
实现了 AccountService 接口的代理对象的任意连接点(在Spring AOP中只是方法执行) : 
this(com.xyz.service.AccountService) 
'this'在binding form中用的更多:- 请常见以下讨论通知的章节中关于如何使得代理对象可以在通知体内访问到的部分。 
实现了 AccountService 接口的目标对象的任意连接点(在Spring AOP中只是方法执行) : 
target(com.xyz.service.AccountService) 
'target'在binding form中用的更多:- 请常见以下讨论通知的章节中关于如何使得目标对象可以在通知体内访问到的部分。 
任何一个只接受一个参数,且在运行时传入的参数实现了 Serializable 接口的连接点 (在Spring AOP中只是方法执行) 
args(java.io.Serializable) 
'args'在binding form中用的更多:- 请常见以下讨论通知的章节中关于如何使得方法参数可以在通知体内访问到的部分。 请注意在例子中给出的切入点不同于 execution(* *(java.io.Serializable)): args只有在动态运行时候传入参数是可序列化的(Serializable)才匹配,而execution 在传入参数的签名声明的类型实现了 Serializable 接口时候匹配。 
有一个 @Transactional 注解的目标对象中的任意连接点(在Spring AOP中只是方法执行) 
@target(org.springframework.transaction.annotation.Transactional) 
'@target' 也可以在binding form中使用:请常见以下讨论通知的章节中关于如何使得annotation对象可以在通知体内访问到的部分。 
任何一个目标对象声明的类型有一个 @Transactional 注解的连接点(在Spring AOP中只是方法执行) 
@within(org.springframework.transaction.annotation.Transactional) 
'@within'也可以在binding form中使用:- 请常见以下讨论通知的章节中关于如何使得annotation对象可以在通知体内访问到的部分。 
任何一个执行的方法有一个 @Transactional annotation的连接点(在Spring AOP中只是方法执行) 
@annotation(org.springframework.transaction.annotation.Transactional) 
'@annotation' 也可以在binding form中使用:- 请常见以下讨论通知的章节中关于如何使得annotation对象可以在通知体内访问到的部分。 
任何一个接受一个参数,并且传入的参数在运行时的类型实现了 @Classified annotation的连接点(在Spring AOP中只是方法执行) 
@args(com.xyz.security.Classified)

分享到:
评论

相关推荐

    springaop中切入点表达式完整示例代码

    详细介绍spring aop中9种切入点表达式的写法execute、within、this、target、args、@target、@within、@annotation、@args

    spring的AOP和AOP相关概念切入点表达式写法详细说明.emmx

    使用mindmaster打开

    Spring AOP 所有切入点指示符详解.docx

    切入点指示符用来指示切入点表达式目的,,在Spring AOP中目前只有执行方法这一个连接点,Spring AOP支持的AspectJ切入点指示符如下: execution:用于匹配方法执行的连接点; within:用于匹配指定类型内的方法执行...

    SpringBoot下的SpringAOP-day04-源代码

    2.3.5 切入点表达式 2.3.6 定义切面类 2.3.7 让AOP生效 2.3.8 编辑测试类 2.4 AOP形象化的比喻 2.5 关于切入点表达式解析 2.5.1 bean标签写法 2.5.2 within表达式 2.5.3 execution表达式 2.6 按照自定义注解进行拦截...

    Spring AOP配置源码

    <aop:pointcut expression="execution(* com.spring.service..*(..))" id="pointCut"/>声明一个切入点,注意execution表达式的写法 <aop:before method="before" pointcut-ref="pointCut"/> aop前置通知 <aop:after ...

    execution表达式&切入点表达式.txt

    在使用spring框架配置AOP的时候,不管是通过XML配置文件还是注解的方式都需要定义pointcut"切入点

    Spring AOP详细介绍.docx

    (4)Pointcut(切入点):就是带有通知的连接点,在程序中主要体现为书写切入点表达式 (5)AOP代理:AOP框架创建的对象,代理就是目标对象的加强。Spring中的AOP代理可以使JDK动态代理,也可以是CGLIB代理,前者基于接口...

    Aspect自定义springboot的使用.docx

    切面(Aspect):是指横切多个对象的关注点的一个模块化,事务管理就是J2EE应用中横切关注点的很好示例。在Spring AOP中,切面通过常规类(基本模式方法)或者通过使用了注解@...Spring默认使用AspectJ切入点表达式语

    Spring AOP @Aspect 基本用法

    2、 @Pointcut放在方法头上,定义一个可被别的方法引用的切入点表达式。 3、5种通知。 3.1、@Before,前置通知,放在方法头上。 3.2、@After,后置【finally】通知,放在方法头上。 3.3、@AfterReturning,后置...

    spring第四天.pdf

    5. 了解切入点表达式 6. 了解通知类型(五种) 7. 重点掌握aop底层的原理之动态代理机制的概述及差别 8. 重点掌握JDK代理技术之产生代理对象和代理对象执行逻辑分析 9. 重点掌握Cglib代理技术之产生代理对象和代理...

    Spring笔记(面试题)md

    1.什么是Spring框架 2.Spring的特点 3.什么是IOC 4.基于xml的IOC 5.项目案例 6.基于注解的IOC 7.添加包扫描的方式 ...16.AspectJ 的切入点表达式(掌握) 17.AspectJ的前置通知@Before .... .... ....

    java AOP aspectjrt-1.8.14 AOP核心大集合

    spring-aop:AOP核心功能,例如代理工厂等等aspectjweaver:简单理解,支持切入点表达式等等aspectjrt:简单理解,支持aop相关注解等等

    跟我学spring3(1-7)

    【第六章】 AOP 之 6.5 AspectJ切入点语法详解 ——跟我学spring3 【第六章】 AOP 之 6.6 通知参数 ——跟我学spring3 【第六章】 AOP 之 6.7 通知顺序 ——跟我学spring3 【第六章】 AOP 之 6.8 切面实例化模型 ...

    Spring-Reference_zh_CN(Spring中文参考手册)

    7.2.3. AspectJ切入点表达式 7.2.4. 便利的切入点实现 7.2.4.1. 静态切入点 7.2.4.2. 动态切入点 7.2.5. 切入点的基类 7.2.6. 自定义切入点 7.3. Spring的通知API 7.3.1. 通知的生命周期 7.3.2. Spring里的通知类型 ...

    Spring高级之注解驱动开发视频教程

    n 技术详解-切入点表达式详解 l Spring JDBC n 基础应用-JdbcTemplate的使用 n 源码分析-自定义JdbcTemplate n 设计模式-RowMapper的策略模式 n 高级应用-NamedParameterJdbcTemplate的使用 n 源码分析-...

    spring.net中文手册在线版

    12.2.3.Spring.NET提供的切入点实现类 12.2.3.1.静态切入点 12.2.3.2.动态切入点 12.2.4.自定义切入点 12.3.Spring.NET的通知类型 12.3.1.通知的生命周期 12.3.2.通知类型 12.3.2.1.拦截环绕通知 12.3.2.2.前置通知 ...

    Spring 2.0 开发参考手册

    7.2.3. AspectJ切入点表达式 7.2.4. 便利的切入点实现 7.2.5. 切入点的基类 7.2.6. 自定义切入点 7.3. Spring的通知API 7.3.1. 通知的生命周期 7.3.2. Spring里的通知类型 7.4. Spring里的advisor(Advisor)...

    flance#spring-framework-reference-5.1.3#5.5.基于模式的AOP支持1

    因此,在本节中,我们将重点放在新语法上,并将读者引用到上一节(@AspectJ支持)中的讨论,以了解编写切入点表达式和建议参数的绑定。要使用本节中描述的aop命

    Spring中文帮助文档

    7.2.3. AspectJ切入点表达式 7.2.4. 便利的切入点实现 7.2.5. 切入点的超类 7.2.6. 自定义切入点 7.3. Spring的通知API 7.3.1. 通知的生命周期 7.3.2. Spring里的通知类型 7.4. Spring里的Advisor API 7.5. ...

    spring chm文档

    7.2.3. AspectJ切入点表达式 7.2.4. 便利的切入点实现 7.2.5. 切入点的基类 7.2.6. 自定义切入点 7.3. Spring的通知API 7.3.1. 通知的生命周期 7.3.2. Spring里的通知类型 7.4. Spring里的advisor(Advisor)...

Global site tag (gtag.js) - Google Analytics