spring3: Aspectj后置返回通知
Aspectj后置返回通知
接口:
package chapter1.server;
public interface IHelloService2 {
public int sayAfterReturning(String param);
}
接口实现
package chapter1.service.impl;
import chapter1.server.IHelloService2;
public class HelloService2 implements IHelloService2 {
public int sayAfterReturning(String param) {
// TODO Auto-generated method stub
System.out.println("============ say after returning:" + param);
return 1;
}
}
配置:
一定要加:<aop:aspectj-autoproxy/> 启动对Aspectj的支持
<aop:aspectj-autoproxy/>
<bean id="helloService" class="chapter1.service.impl.HelloService2" />
<bean id="aspect" class="chapter1.aop.HelloAspect2"/>
AOP切面:
一定要引入:org.aspectj.lang.annotation.Aspect; 否则不执行
package chapter1.aop; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.AfterReturning; @Aspect
public class HelloAspect2 { //方法一
//通知
@AfterReturning(
//value="execution(* chapter1..*.sayAdvisorBefore(java.lang.String)) and args(param)",
value="execution(* chapter1..*.sayAfterReturning(..))",
argNames="retVal",
returning="retVal")
public void afterReturningAdvice(Object retVal)
{
System.out.println("================= return after advice : " + retVal);
} //方法二
//定义切入点
@Pointcut(value="execution(* chapter1..*.sayAfterReturning(java.lang.String) and args(param))", argNames="param")
public void returnPointcut(String param) {} public void afterReturningAdvice2(Object retVal)
{ } }
测试程序:
@Test
public void testAspectAfterReturning()
{
ApplicationContext context = new ClassPathXmlApplicationContext("chapter1/aspectj2.xml");
IHelloService2 hello = context.getBean("helloService", IHelloService2.class);
hello.sayAfterReturning("hahah");
}
结果:
============ say after returning:hahah
================= return after advice : 1
spring3: Aspectj后置返回通知的更多相关文章
- AOP 环绕通知 集成了前置 后置 返回通知等功能
AOP 环绕通知 集成了前置 后置 返回通知等功能
- C++:重载前置++/--返回引用,重载后置++/--返回临时对象
标准库中iterator对++/--的重载代码如下: _Myiter& operator++() { // preincrement ++*(_Mybase *)this; return (* ...
- 【M6】区别increment/decrement操作符的前置(prefix)和后置(postfix)形式
1.考虑++(--的情况是一样的),前置是累加然后取出,后置是取出然后累加. 2.重载方法根据形参表的不同区分,问题来了,前置和后置形式都没有形参,因此没法区分.怎么办? 对于后置增加一个形参int, ...
- C++之运算符重载(前置++和后置++)
今天在阅读<google c++ 编程风格>的文档的时候,5.10. 前置自增和自减:有一句话引起了我的注意: 对于迭代器和其他模板对象使用前缀形式 (++i) 的自增, 自减运算符.,理 ...
- [原创]java WEB学习笔记106:Spring学习---AOP的通知 :前置通知,后置通知,返回通知,异常通知,环绕通知
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- 13Spring_AOP编程(AspectJ)_后置通知
后置通知和前置通知差不多.最大的特点是因为后置通知是运行在目标方法之后的,所以他可以拿到目标方法的运行的结果. 给出案例: 案例结构图:
- Spring(十八):Spring AOP(二):通知(前置、后置、返回、异常、环绕)
AspectJ支持5种类型的通知注解: @Before:前置通知,在方法执行之前执行: @After:后置通知,在方法执行之后执行: @AfterRunning:返回通知,在方法返回结果之后执行(因此 ...
- Spring初学之xml实现AOP前置通知、后置通知、返回通知、异常通知等
实现两个整数的加减乘除,在每个方法执行前后打印日志. ArithmeticCalculator.java: package spring.aop.impl.xml; public interface ...
- Spring初学之annotation实现AOP前置通知、后置通知、返回通知、异常通知。
实现两个整数的加减乘除.在执行每个方法之前打印日志. ArithmeticCalculator.java: package spring.aop.impl; public interface Arit ...
随机推荐
- python基础之练习题(一)
1.执行 Python 脚本的两种方式 python test.py chmod +x test.py && ./test.py 2.简述位.字节的关系 二进制位(bit)是计算机存储 ...
- [TensorFlow] tf.nn.softmax_cross_entropy_with_logits的用法
在计算loss的时候,最常见的一句话就是tf.nn.softmax_cross_entropy_with_logits,那么它到底是怎么做的呢? 首先明确一点,loss是代价值,也就是我们要最小化的值 ...
- HDFS各个进程存储在磁盘上的数据含义和注意事项
本文地址:http://www.cnblogs.com/qiaoyihang/p/6293402.html (一)Namenode的目录结构 HDFS进行初次格式化之后将会在$dfs.namenode ...
- Hive学习路线图--张丹老师
前言 Hive是Hadoop家族中一款数据仓库产品,Hive最大的特点就是提供了类SQL的语法,封装了底层的MapReduce过程,让有SQL基础的业务人员,也可以直接利用Hadoop进行大数据的操作 ...
- Pimpl Idiom /handle body idiom
在读<Effective C++>和项目源代码时,看到pImpl Idiom.它可以用来降低文件间的编译依赖关系,通过把一个Class分成两个Class,一个只提供接口,另一个负责实现该接 ...
- Django CSRF cookie not set.错误
post提交表单报错: Forbidden (403) CSRF verification failed. Request aborted. You are seeing this message b ...
- java实现简单邮件的发送以及常见问题
java实现简单邮件的发送以及常见问题 最近遇到个需求需要实现发送邮件的功能,以前做发送邮件功能都是有邮箱用户名密码,通过用户名密码连接对应的SMTP服务器来实现邮件的发送.但是这次用公司内部的邮箱, ...
- ASYNCAPI
https://www.asyncapi.com Introduction AsyncAPI provides a specification that allows you to define Me ...
- Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration info
Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the ...
- python3:利用smtplib库和smtp.qq.com邮件服务器发送邮件
python3:利用smtplib库和smtp.qq.com邮件服务器发送邮件 使用qq的邮件服务器需要注意的两个地方主要是: 1.协议问题 使用465端口 SSL 协议 2.口令问题 出现SMTPA ...