Spring学习笔记:使用Pointcut 和Advisor实现AOP
基础知识
在 Spring AOP 中,有 3 个常用的概念,Advices 、 Pointcut 、 Advisor ,解释如下:
- Advices :表示一个 method 执行前或执行后的动作。
- Pointcut :表示根据 method 的名字或者正则表达式去拦截一个 method 。
- Advisor : Advice 和 Pointcut 组成的独立的单元,并且能够传给 proxy factory 对象。
用xml配置Pointcut
<bean id="Pointcut的Id" class="org.springframework.aop.support.NameMatchMethodPoint">
<property name="mappedName" vlaue="方法名"/>
</bean>
用xml配置Advisor,将pointcut与advice关联起来
<bean id="Advisor的Id" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="pointcut" ref="要关联的Pointcut"/>
<property name="advice" ref="要关联的Advice"/>
</bean>
用xml配置代理类
<bean id="生成的代理的Id" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="要代理的类(即需要劫持的类)"/>
<property>
<list>
<value>Advisor的Id</value>
</list>
</property>
</bean>
不单独配置Pointcut,在配置Advisors时class选择NameMatchMethodPointcutAdvisor
<bean id="Advisor的Id" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
<property name="mappedName" value="方法名"/>
<property name="advice" ref="要关联的Advice" />
</bean>
创建使用正则表达式匹配要拦截的method的切点
在class中选择org.springframework.aop.support.RegexpMethodPointcutAdvisor
<bean id="Advisor名" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="patterns">
<list>
<value>.*URL.*</value>
</list>
</property>
<property name="advice" ref=""/>
</bean>
Spring学习笔记:使用Pointcut 和Advisor实现AOP的更多相关文章
- Java框架spring 学习笔记(十二):aop实例操作
使用aop需要在网上下载两个jar包: aopalliance.jar aspectjweaver.jar 为idea添加jar包,快捷键ctrl+shift+alt+s,打开添加jar包的对话框,将 ...
- spring学习笔记(三)我对AOP理解
首先我们要知道AOP是什么?AOP全称Aspect OrientedProgramming,即面向切面编程.在这里我不想去说什么是切面,什么是切点,什么是通知等等,相关博客很多,如果大家想知道可以自己 ...
- Java框架spring 学习笔记(十八):事务管理(xml配置文件管理)
在Java框架spring 学习笔记(十八):事务操作中,有一个问题: package cn.service; import cn.dao.OrderDao; public class OrderSe ...
- 不错的Spring学习笔记(转)
Spring学习笔记(1)----简单的实例 --------------------------------- 首先需要准备Spring包,可从官方网站上下载. 下载解压后,必须的两个包是s ...
- 【Spring学习笔记-MVC-3.1】SpringMVC返回Json数据-方式1-扩展
<Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...
- spring学习笔记(一) Spring概述
博主Spring学习笔记整理大部分内容来自Spring实战(第四版)这本书. 强烈建议新手购入或者需要电子书的留言. 在学习Spring之前,我们要了解这么几个问题:什么是Spring?Spring ...
- Spring学习笔记2——表单数据验证、文件上传
在上一章节Spring学习笔记1——IOC: 尽量使用注解以及java代码中,已经搭建了项目的整体框架,介绍了IOC以及mybatis.第二节主要介绍SpringMVC中的表单数据验证以及文件上传. ...
- 【Spring学习笔记-MVC-15.1】Spring MVC之异常处理=404界面
作者:ssslinppp 异常处理请参考前篇博客:<[Spring学习笔记-MVC-15]Spring MVC之异常处理>http://www.cnblogs.com/sssl ...
- 【Spring学习笔记-MVC-13.2】Spring MVC之多文件上传
作者:ssslinppp 1. 摘要 前篇文章讲解了单文件上传<[Spring学习笔记-MVC-13]Spring MVC之文件上传>http://www.cnblogs.co ...
随机推荐
- hexo零基础搭建博客系列(一)
关于其他搭建 [hexo4快速搭建博客(二)更换主题](https://blog.csdn.net/weixin_41800884/article/details/103750634)[hexo4快速 ...
- 6、使用基元类型而不要使用 FCL 类型
基元类型: int string object uint long ulong 等 ; FCL (Framework Class Library ) System.Int32 等. 一些定义在一些语言 ...
- 区间dp - 送外卖
When we are focusing on solving problems, we usually prefer to stay in front of computers rather tha ...
- CentOS 7.2 搭建Jenkins
1,准备阶段 jenkins下载 https://jenkins.io/download/ 这里我们选择稳定版本 (本文介绍的是通过tomcat来部署的,由于jenkins内部也集成了容器,也可直接通 ...
- .net core 第三方工具包集合
日志 Nlog 单点登录
- 关于C++读入数字按位取出与进制转换问题
这一片博客我就不写具体的一个题了,只是总结一种典型问题——读入数字按位取出. 就拿数字12345举例吧. 是首先,我们要取出个位.这样取出: 12345/1=12345 12345%10=5. ...
- 阿里巴巴Jetcache springboot使用教程
原文地址:https://www.jianshu.com/p/03b289439de2 springboot中使用说明 jetcache原理参见:https://www.jianshu.com/p/8 ...
- python类型-序列-列表
列表类型也是序列式的数据类型,可通过下标或者切片操作来访问某一个或某一块连续的元素. 列表的元素是可变的,可包含不同类型的元素,列表类型的元素可以是另一个序列类型. 1.创建列表类型数据并赋值 列表使 ...
- 使用Razor表达式 使用条件语句 来自 精通ASP-NET-MVC-5-弗瑞曼
- selenium,统计某分支下有多少个同类子分支的方法(用于循环获取同类型子分支属性值)
利用selenium自动化统计微博阅读数 查看微博阅读数的元素路径 微博列表中第一条微博的元素路径“//*[@id="Pl_Official_MyProfileFeed__20"] ...