博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring aop 申明了切面类之后,如何申明切入点呢?
阅读量:5969 次
发布时间:2019-06-19

本文共 2983 字,大约阅读时间需要 9 分钟。

hot3.png

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 expressionprivate 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  (and for extensions, the ) 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  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

你可能感兴趣的文章
swift基础之_swift调用OC/OC调用swift
查看>>
Devexpress 15.1.8 Breaking Changes
查看>>
ElasticSearch Client详解
查看>>
mybatis update返回值的意义
查看>>
expdp 详解及实例
查看>>
通过IP判断登录地址
查看>>
深入浅出JavaScript (五) 详解Document.write()方法
查看>>
Beta冲刺——day6
查看>>
在一个程序中调用另一个程序并且传输数据到选择屏幕执行这个程序
查看>>
代码生成工具Database2Sharp中增加视图的代码生成以及主从表界面生成功能
查看>>
关于在VS2005中编写DLL遇到 C4251 警告的解决办法
查看>>
提高信息安全意识对网络勒索病毒说不
查看>>
使用Jquery 加载页面时调用JS
查看>>
css+div+jquery弹出层
查看>>
求职相关(链接,不定期更新)
查看>>
maya pyside 多个窗口实例 报错 解决
查看>>
我的友情链接
查看>>
通知中心
查看>>
我的友情链接
查看>>
MVC中的三个模块
查看>>