【转】http://www.cnblogs.com/softidea/p/6123307.html

话不多说,直接上代码:

package com.cdms.aop.aspectImpl;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component; import java.util.Arrays;
import java.util.List; /**
* 创建 by 草帽boy on 2017/4/1.
*/
@Aspect
@Component
public class ICacheAopAction {
@Pointcut("@annotation(com.cdms.aop.ICache)")
private void controllerAspect(){} @Before("controllerAspect()")
public void Before(JoinPoint joinPoint){
String classname = joinPoint.getTarget().getClass().getSimpleName();
String methodName = joinPoint.getSignature().getName();
List<Object> args = Arrays.asList(joinPoint.getArgs());
System.out.println("@before Execute! --class name: " + classname + ", method name: " + methodName + " " + args );
} @Around("controllerAspect()")
public Object Around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
System.out.println("@Around:执行目标方法之前...");
Object obj= proceedingJoinPoint.proceed();
System.out.println("@Around:执行目标方法之后...");
System.out.println("@Around:被织入的目标对象为:" + proceedingJoinPoint.getTarget());
System.out.println( "@Around:原返回值:" + obj + ",这是返回结果的后缀");
return obj;
} @AfterThrowing("controllerAspect()")
public void AfterThrowing(){
System.out.println("异常通知....");
} @After("controllerAspect()")
public void After(JoinPoint point){
System.out.println("@After:模拟释放资源...");
System.out.println("@After:目标方法为:" +
point.getSignature().getDeclaringTypeName() +
"." + point.getSignature().getName());
System.out.println("@After:参数为:" + Arrays.toString(point.getArgs()));
System.out.println("@After:被织入的目标对象为:" + point.getTarget());
} @AfterReturning("controllerAspect()")
public void AfterReturning(JoinPoint point){
System.out.println("@AfterReturning:模拟日志记录功能...");
System.out.println("@AfterReturning:目标方法为:" +
point.getSignature().getDeclaringTypeName() +
"." + point.getSignature().getName());
System.out.println("@AfterReturning:参数为:" +
Arrays.toString(point.getArgs()));
System.out.println("@AfterReturning:返回值为:" );
System.out.println("@AfterReturning:被织入的目标对象为:" + point.getTarget());
} }

测试的结果是:

这样就很清楚的看出各种方法是在什么时候调用的啦

关于Aop切面中的@Before @Around等操作顺序的说明的更多相关文章

  1. spring aop切面中获取代理bean的名字以及bean

    //切面中搞: Map<String , Object> map = (Map)ApplicationContextHelper.getBean(proceedingJoinPoint.g ...

  2. spring Aop切面中的@Before @Around等执行顺序与请求参数统一解码

    1.背景 在实际开发中,我可能会对请求接口做统一日志输出,或者统一参数解析,验签,统一响应加密等,通常会用到aop,实际案例如下 2.代码 package com.qianxingniwo.log; ...

  3. 如何优雅地在 Spring Boot 中使用自定义注解,AOP 切面统一打印出入参日志 | 修订版

    欢迎关注个人微信公众号: 小哈学Java, 文末分享阿里 P8 资深架构师吐血总结的 <Java 核心知识整理&面试.pdf>资源链接!! 个人网站: https://www.ex ...

  4. Spring AOP——Spring 中面向切面编程

    前面两篇文章记录了 Spring IOC 的相关知识,本文记录 Spring 中的另一特性 AOP 相关知识. 部分参考资料: <Spring实战(第4版)> <轻量级 JavaEE ...

  5. Spring Boot 中使用自定义注解,AOP 切面打印出入参日志及Dubbo链路追踪透传traceId

    一.使用背景 开发排查系统问题用得最多的手段就是查看系统日志,在分布式环境中一般使用 ELK 来统一收集日志,但是在并发大时使用日志定位问题还是比较麻烦,由于大量的其他用户/其他线程的日志也一起输出穿 ...

  6. 利用AOP切面打印项目中每个接口的运行情况

    1.前言 AOP切面技术,大家应该都听知道,Spring框架的主要功能之一. AOP切面的用途很广,其中一个常见的用途就是打印接口方法的运行日志和运行时间. 日志对于一个项目很是重要,不仅有助于调错, ...

  7. Spring aop切面插入事物回滚

    <!-- tx标签配置 事物--> <tx:advice id="txadvice" transaction-manager="transactionM ...

  8. Spring MVC通过AOP切面编程 来拦截controller 实现日志的写入

    首选需要参考的是:[参考]http://www.cnblogs.com/guokai870510826/p/5977948.html    http://www.cnblogs.com/guokai8 ...

  9. Spring Boot 2.0 教程 | AOP 切面统一打印请求日志

    欢迎关注微信公众号: 小哈学Java 文章首发于个人网站 https://www.exception.site/springboot/spring-boot-aop-web-request 本节中,您 ...

随机推荐

  1. Poj1543

    Perfect Cubes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16522   Accepted: 8444 De ...

  2. 关于elementui表单数字校验踩坑记

    需求:1.输入类型是数字.2.数字大小有限制.3.非必填 做法: <el-form-item label="熟悉程度" prop="averageCaseRunTi ...

  3. 读书笔记之_Win10 与Jmeter5.1.1界面兼容:

    读书笔记之win10 与jmeter5.1.1界面兼容:   调整前:

  4. [20190419]shared latch spin count 2.txt

    [20190419]shared latch spin count 2.txt --//上午测试shared latch XX模式的情况,链接:http://blog.itpub.net/267265 ...

  5. Python之Pandas的一些理解

    Pandas的功能: 1.  结构化的数据分析; 相比excel,可以处理更大量的数据和更好的性能 2.  对数据的清洗

  6. PYQT5登录界面跳转主界面方法

    该问题,有很多种方法,但是很多方法要么这个有问题,要么那个有问题,最后终于找到一种没问题的方法.记录一下: 参考地址:https://www.jianshu.com/p/d18ff36a78d6?fr ...

  7. 记录未预编译文件“*.aspx”,因此不能请求该文件的几种处理办法

    对应Framework版本重新注册 2.0:C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i 4.0:C:\Wind ...

  8. Flink监控:Monitoring Apache Flink Applications

    This post originally appeared on the Apache Flink blog. It was reproduced here under the Apache Lice ...

  9. background问题

    1.如果是小图的背景图 background: url("@{images-dir}/homepage/our_pro_2x.png") no-repeat 0 0; backgr ...

  10. 身边有个漂亮的java女程序员是什么体验?

    程序员都是一些追求完美的人.女程序员细致认真,不仅能写代码而且注释详尽清晰.能做好单元测试BUG最少.能写标准规范的设计文件不会对不上模块编号也不会少了类或接口说明,提交代码不会忘记写LOG,不会和测 ...