spring学习 十二 AspectJ-based的通知入门 带参数的通知
第一步:编写通知类
package com.airplan.pojo;
import org.aspectj.lang.ProceedingJoinPoint;
public class Advice {
public void mybefore(String name1,int age1){
System.out.println("前置"+name1 );
}
public void mybefore1(String name1){
System.out.println("前置:"+name1);
}
public void myaftering(){
System.out.println("后置 2");
}
public void myafter(){
System.out.println("后置 1");
}
public void mythrow(){
System.out.println("异常");
}
public Object myarround(ProceedingJoinPoint p) throws Throwable{
System.out.println("执行环绕");
System.out.println("环绕-前置");
Object result = p.proceed();
System.out.println("环绕后置");
return result;
}
}
第二步配置
2 配置 spring 配置文件
2.1 <aop:after/> 后置通知,是否出现异常都执行
2.2 <aop:after-returing/> 后置通知,只有当切点正确执行时执行
2.3 <aop:after/> 和 <aop:after-returing/> 和<aop:after-throwing/>执行顺序和配置顺序有关
2.4 execution() 括号不能扩上 args
2.5 中间使用 and 不能使用&& 由 spring 把 and 解析成&&
2.6 args(名称) 名称自定义的.顺序和 demo1(参数,参数)对应
2.7 <aop:before/> arg-names=” 名 称 ” 名 称 来 源 于expression=”” 中 args(),名称必须一样
2.7.1 args() 有几个参数,arg-names 里面必须有几个参数
2.7.2 arg-names=”” 里面名称必须和通知方法参数名对应
<aop:config>
<aop:aspect ref="myadvice">
<!--
args(name1,age1):args中的参数必须与<aop:before />标签中arg-names的属性值一致
-->
<aop:pointcut expression="execution(* com.bjsxt.test.Demo.demo1(String,int)) and args(name1,age1)" id="mypoint"/> <aop:before method="mybefore" pointcut-ref="mypoint" arg-names="name1,age1"/> </aop:aspect>
</aop:config>
上面标蓝的部分一定要一致,并且要与通知方法的参数对应,连名称也要一样,虽然切点的参数名称不要求和args中的名称对应,但是数量要对应
spring学习 十二 AspectJ-based的通知入门 带参数的通知的更多相关文章
- Spring学习(十二)-----Spring @PostConstruct和@PreDestroy实例
实现 初始化方法和销毁方法3种方式: 实现标识接口 InitializingBean,DisposableBean(不推荐使用,耦合性太高) 设置bean属性 Init-method destroy- ...
- Spring学习(十二)-----Spring Bean init-method 和 destroy-method实例
实现 初始化方法和销毁方法3种方式: 实现标识接口 InitializingBean,DisposableBean(不推荐使用,耦合性太高) 设置bean属性 Init-method destroy- ...
- Spring学习十二----------Bean的配置之@ImportResource和@Value
© 版权声明:本文为博主原创文章,转载请注明出处 @ImportResource -引入XML配置文件 @Value -从配置文件中获取值 实例 1.项目结构 2.pom.xml <projec ...
- spring学习十二 application/x-www-form-urlencoded还是application/json
application/x-www-form-urlencoded还是application/json get. POST 用哪种格式? 后台如何得到这些值? 如何用ajax 或者是 postman ...
- Spring Boot(十二):spring boot如何测试打包部署
Spring Boot(十二):spring boot如何测试打包部署 一.开发阶段 1,单元测试 在开发阶段的时候最重要的是单元测试了,springboot对单元测试的支持已经很完善了. (1)在p ...
- spring 学习(二):spring bean 管理--配置文件和注解混合使用
spring 学习(二)spring bean 管理--配置文件和注解混合使用 相似的,创建 maven 工程,配置pom.xml 文件,具体可以参考上一篇博文: sprint 学习(一) 然后我们在 ...
- (转)SpringMVC学习(十二)——SpringMVC中的拦截器
http://blog.csdn.net/yerenyuan_pku/article/details/72567761 SpringMVC的处理器拦截器类似于Servlet开发中的过滤器Filter, ...
- spring学习 十一 AspectJ-based的通知入门 不带参数的通知
AspectJ-Based方式的AOP,通知类不需要实现任何接口,且前置通知,后置通知,环绕通知,异常通知都可以写在一个类中,下面先实现一个简单的,不带参数的通知. 第一步定义通知类,通知类中的通知( ...
- iOS NSNotification传递带参数的通知
普通的通知使用 注册观察者 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getNotificat ...
随机推荐
- lower_bound和upper_bound的实现和基本用法
最近一直在学dp,但是感觉进度明显慢了很多,希望自己可以加一把劲,不要总是拖延了... 在LIS的优化中我遇到了二分查找的问题,之前也知道lower_bound和upper_bound两个函数,但是没 ...
- 自动化测试之selenium工具简单介绍
一.selenium简单介绍 1.selenium的成员 2.selenium工作原理 二.webdrive 常见元素定位
- django序列化单表的4种方法的介绍
这里主要是讲序列化单表的几种方法 先看下models中设计的表结构 from django.db import models # Create your models here. class Book ...
- Django使用jsonp和cors解决跨域请求问题
1.使用jsonp的方式解决跨域请求的问题 我启动两个django项目,然后使用的端口不一样,在项目1中通过ajax发请求给项目2,然后接受项目2发送过来的数据 先看项目1的ajax的代码 $(&qu ...
- java 基础之--传统网络编程
什么是socket ? socket 是连接运行在网络上的两个程序间的双向通讯端点 服务器将某一套接字绑定到一个特定的端口,并通过这一套接字等待和监听客户端的的连接请求 客户端通过这个端口与服务器进行 ...
- Django创建模型,迁移数据
1.在models.py文件中添加代码 class notice(models.Model): notice_title = models.CharField(max_length=255) noti ...
- echarts柱状图图例不显示的问题
如果想要图例有效果,legend中数据要和series中name的值保持一致,切记切记,这是我曾经遇到的坑,不保持一致是没有效果的
- ABP框架使用Swagger
参考文档:https://www.cnblogs.com/xcsn/p/7910890.html 步骤1:Nuget安装Swashbuckle到*.WebApi项目 步骤2:在*.WebApi> ...
- MSDos
一.简介 二.源码 http://www.computerhistory.org/atchm/microsoft-research-license-agreement-msdos-v1-1-v2- ...
- hdu 1059 (多重背包) Dividing
这里;http://acm.hdu.edu.cn/showproblem.php?pid=1059 题意是有价值分别为1,2,3,4,5,6的商品各若干个,给出每种商品的数量,问是否能够分成价值相等的 ...