springAOP 的pointcut
<bean id="amqFilter" class="com.xxx.hotel.base.aspectj.AmQConsumerFilter"/>
<aop:config proxy-target-class="true">
<aop:aspect ref="amqFilter">
<aop:before method="beforeOnMessage" arg-names="message"
pointcut="execution(* xxx.amq.MessageListener.onMessage(..)) and args(message)"/>
</aop:aspect>
</aop:config>
那么pointcut后边的表达式说明了哪些方法需要被aop所执行,可以有args() @args() execution() target() @target() @annotation等来定义或组合(&& , || , !)
其中比较常见的是execution,例子如下:
任意公共方法的执行
execution(public * *(..))
任意一个以get开头的方法的执行
execution(* get*(..))
hotelService接口的任意方法
execution(* com.balfish.hotel.service.HotelService.*(..))
service包里的任意方法的执行
execution(* com.balfish.hotel.service.*.*(..))
service包和所有子包里的任意类的任意方法的执行
execution(* com.balfish.hotel.service..*.*(..))
总结:靠近(..)的是方法,靠近.*(..)的是类或接口
Pointcut 可以通过Java注解和XML两种方式配置,如下所示:
<aop:config>
<aop:aspectref="aspectDemo">
<aop:pointcutid="pointcut"expression="execution(* com.balfish.spring.aop.pointcut..JoinPointTest.*(..))"/>
<aop:before pointcut-ref="pointcut" method="beforeAdvice" />
</aop:aspect>
</aop:config>
@Component
@Aspect
public class AspectDemo {
//@Pointcut("execution(* com.balfish.spring.aop.pointcutexp..JoinPointObjP2.*(..))")
//@Pointcut("within(com.balfish.spring.aop.pointcutexp..*)")
//@Pointcut("this(com.balfish.spring.aop.pointcutexp.Intf)")
//@Pointcut("target(com.balfish.spring.aop.pointcutexp.Intf)")
//@Pointcut("@within(org.springframework.transaction.annotation.Transactional)")
//@Pointcut("@annotation(org.springframework.transaction.annotation.Transactional)")
@Pointcut("args(String)")
public void pointcut() {
}
@Before(value = "pointcut()")
public void beforeAdvice() {
System.out.println("pointcut1 @Before...");
}
springAOP 的pointcut的更多相关文章
- 0 can't find referenced pointcut declarePointExpress
今天在用SpringAOP 的 @pointCut 的时候报错 Exception in thread "main" org.springframework.beans.facto ...
- Spring4.0学习笔记(11) —— Spring AspectJ 的五种通知
Spring AspectJ 一.基于注解的方式配置通知 1.额外引入的jar包: a) com.springsource.org.aopalliance-1.0.0.jar b) com.sprin ...
- spring中AOP的AspectJ的Execution表达式
AspectJ的Execution表达式: 使用springAOP定义pointcut里面的execution表达式: execution()函数是常用的切点函数 "execution(* ...
- [Done]Spring @Pointcut 切点调用不到(SpringAOP嵌套方法不起作用) 注意事项
今天在开发过程中,遇到一个问题卡了很久,测试代码如下: package spring.pointcut; import org.aspectj.lang.ProceedingJoinPoint; im ...
- springAOP注解方式定义切入点报错error at ::0 can't find referenced pointcut
[说明] 1.使用spring版本:4.0.4 2.springAOP相关依赖包: 1)aopalliance-1.0.jar 2)aspectjweaver-1.8.9.jar 3)aspectjr ...
- SpringAOP学习第一天 @Pointcut注解
自从上班之后,就很少再看AOP相关的内容,几年时间里虽然也有一两次完整看过,一直没有机会用到,都忘记了.今天重温一下 TestNG测试类 package com.test.spring.aop.min ...
- jdk1.8+SpringAOP注解报java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut select错误的不知原因的解决办法[仅供参考]
先说办法:如果Aspectweaver-1.*.*jar这三个包版本比较低, 比如1.5.0这一层次的,可以找版本高一点的包替换低版本的包,问题可以得到解决 jar包的下载地址:https://mvn ...
- springAOP配置XML方式配置切面报错error at ::0 formal unbound in pointcut
[错误配置文件] <aop:config> <aop:pointcut expression="execution(* net.fifteenho.service.impl ...
- SpringAOP注解报错:java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut selectAll
原因 我使用的aspectjweaver.jar版本是1.5.1,版本过低,导致报错. 需要下载高本版的aspectjweaver.jar. 解决办法 在这里下载:https://mvnreposit ...
随机推荐
- 图的两种遍历:DFS&BFS
DFS和BFS在图中的应用: 图连通性判定:路径的存在性:图中是否存在环:求图的最小生成树:求图的关键路径:求图的拓扑排序. DFS:简单的说,先一直往深处走,直到不能再深了,再从另一条路开始往深处走 ...
- hdu_5193_Go to movies Ⅱ(带插入删除的逆序对,块状链表)
题目链接:hdu_5193_Go to movies Ⅱ 题意: 有n个人站成一排,每个人的身高为Hi.每次有人加入或者有人离开,就要判断有多少人站反了(i < j&&Hi> ...
- 一步一步学EF系列 【7、结合IOC ,Repository,UnitOfWork来完成框架的搭建】
前言 距离上一篇已经有段时间了,最近这段时间赶上新项目开发,一直没有时间来写.之前的几篇文章,主要把EF的基础都讲了一遍,这批文章就来个实战篇. 个人在学习过程中参考博客: Entity Framew ...
- LeetCode OJ 123. Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- SharePoint 2013 配置InfoPath 列表表单
转载来源:http://www.cnblogs.com/jianyus/p/3470113.html SharePoint列表,都是通过表单展示,有时候不太符合要求,这时候,我们可以通过定制表单,来是 ...
- Python使用shape计算矩阵的行和列
shape函数是numpy.core.fromnumeric中的函数,它的功能是读取矩阵的长度. 1 >>> a=mat([[1,2,3],[5,6,9]]); 2 >> ...
- Oracle 获取当天数据
where trunc(to_date(DATETIME,'yyyy-MM-dd hh24:mi:ss'))=trunc(sysdate)
- 用VBS控制鼠标的实现代码(获取鼠标坐标、鼠标移动、鼠标单击、鼠标双击)
网上搜到的答案普遍是VBS无法实现,或者是要用第三方COM(ActiveX?)组件.我对第三方组件是很反感的,使用第三方组件毫无可移植性可言,因为别人的系统中不一定注册了这个组件.我的建议是,尽量不要 ...
- MFC中组合框CComboBox的使用
假如添加三行数据,其中当选择前两行时,提示自定义提示框信息,选择第三行时,提示当前字符串的内容,实现如下: void Cuse_demo_dllDlg::OnCbnSelchangeCombo1(){ ...
- leetcode342合理运用位操作判断4的幂
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Gi ...