Spring AOP 创建Advice 定义pointcut、advisor
前面定义的advice都是直接植入到代理接口的执行之前和之后,或者在异常发生时,事实上,还可以对植入的时机定义的更细。
Pointcut定义了advice的应用时机,在Spring中pointcutAdvisor将pointcut和advice结合成一个对象,spring内建的pointcut都对应着pointcutAdvisor,常见的有下面两种:

NameMatchMethodPointcutAdvisor:他是最基本的pointcutAdvisor,是静态pointcut的实例,你可以指定advice所要应用的目标方法名称,或者用*来指定。例如 hello* 代表以hello开头的所有方法名称,都要应用到指定的advice上。
RegExpMethodPointcutAdvisor:可以让你用正则表达式的方式来定义pointcut,他是静态pointcut实例,在符合正则表达式的情况下,应用到指定的advice上。其中,bean中有一个pattern属性,用于写入正则表达式


public interface IHello {
public void sayHello(String str) throws Exception;
public void sayHelloChina(String str);
public void sayHelloEnglish(String str);
}
public class Hello implements IHello {
@Override
public void sayHello(String str) throws Exception {
System.out.println("你好"+str);
//测试抛出异常
throw new Exception("故意造成异常!");
}
@Override
public void sayHelloChina(String str) {
System.out.println("你好"+str);
}
@Override
public void sayHelloEnglish(String str) {
System.out.println("Hello"+str);
}
}
hello.sayHelloChina("中国");
hello.sayHelloEnglish("美国");
Spring AOP 创建Advice 定义pointcut、advisor的更多相关文章
- Spring AOP 创建Advice 基于Annotation
public interface IHello { public void sayHello(String str); } public class Hello implements IHello { ...
- Spring横切面(advice),增强(advisor),切入点(PointCut)(转)
Spring横切面(advice),增强(advisor),切入点(PointCut)的一点理解: 1.Spring管理事务有2种,其中一种是HibernateTransactionManager管理 ...
- Spring AOP 创建切面
增强被织入到目标类的所有方法中,但是如果需要有选择性的织入到目标类某些特定的方法中时,就需要使用切点进行目标连接点的定位.增强提供了连接点方位信息:如织入到方法前面.后面等,而切点进一步描述织 ...
- Spring AOP 创建增强类
AOP联盟为增强定义了org.aopalliance.aop.Advice接口,Spring支持5种类型的增强: 1)前置增强:org.springframework.aop.BeforeAd ...
- Spring AOP高级——源码实现(2)Spring AOP中通知器(Advisor)与切面(Aspect)
本文例子完整源码地址:https://github.com/yu-linfeng/BlogRepositories/tree/master/repositories/Spring%20AOP%E9%A ...
- Spring AOP Example – Advice
Spring AOP + AspectJ Using AspectJ is more flexible and powerful. Spring AOP (Aspect-oriented progra ...
- Spring AOP增强(Advice)
Sring AOP通过PointCut来指定在那些类的那些方法上织入横切逻辑,通过Advice来指定在切点上具体做什么事情.如方法前做什么,方法后做什么,抛出异常做什么. Spring中有两种方式定义 ...
- Spring AOP 使用注解定义切面(转载)
原文地址:http://www.jianshu.com/p/6f40dddd71a5 1.定义切面 下面我们就来定义一场舞台剧中观众的切面类Audience: package com.spring.a ...
- Spring AOP 中 advice 的四种类型 before after throwing advice around
spring AOP(Aspect-oriented programming) 是用于切面编程,简单的来说:AOP相当于一个拦截器,去拦截一些处理,例如:当一个方法执行的时候,Spring 能够拦截 ...
随机推荐
- Xshell远程登录
1.xshell由一台服务器a登录另一台服务器b sftp -oPort = root@ip 2.下载git /上传pull git b服务器想下载的目标文件目录 a服务器上的文件下载目录
- How to receive a million packets per second
Last week during a casual conversation I overheard a colleague saying: "The Linux network stack ...
- 【深入学习linux】在linux系统下怎么编写c语言程序并运行
1. 首先安装下 gcc : centos yum -y gcc 2. 编写c程序保存hello.c: #include <stdio.h> #include <stdlib.h&g ...
- MySQL索引原理(一)
MySQL索引原理 索引目的 索引的目的在于提高查询效率,可以类比字典,如果要查“mysql”这个单词,我们肯定需要定位到m字母,然后从下往下找到y字母,再找到剩下的sql.如果没有索引,那么你可能需 ...
- 018 oauth协议
1.作用 2.流程步骤 3.授权模式 4.授权码模式
- 小米手机root
目录 概念 解锁流程 root流程 如何Root? 关于supersu 关于twrp 关于Magisk Manager ref: 申请开发板流程 线刷教程 小米手机root 概念 解锁: 使手机可以刷 ...
- spring boot项目maven打包可执行JAR
在pom.xml中添加如下配置: <!-- 打包可执行jar包 --> <plugin> <groupId>org.springframework.boot< ...
- pip安装yaml
1.安装:输入pip install pyyaml或者pip3 install pyyaml 2.检查是否安装成功:输入python
- django注释
转自https://www.cnblogs.com/dayouzi/p/10154815.html Django在HTML里面书写的模板语言不能使用这种方法注释,这样注释实际依然有效 <!--{ ...
- 我最近买的书里面带的CD盘,放电脑里后,说是0字节,但是可以播放,不能把里面的东西复制出来
我最近买的书里面带的CD盘,放电脑里后,说是0字节,但是可以播放,不能把里面的东西复制出来,有track1,track2之类的文件,都只有几十字节大,请问有没有什么方法把里面的音乐复制出来??? 用w ...