添加springboot-aop的starter

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
编写切面代码(先执行环绕方法->方法前->方法后->方法返回后,开启环绕方法时,异常方法无效)
@Aspect
@Component
public class AspectService {
//coder.rdf.mybatis.study.service包下的所有类的所有方法
@Before(value="execution(* coder.rdf.mybatis.study.service.*.*(..))")
public void before(JoinPoint joinPoint) throws Throwable {
Object[] args = joinPoint.getArgs();
String name = joinPoint.getSignature().getName();
System.out.println("方法前****切面方法**"+name+"***"+ Arrays.toString(args));
}

@After(value="execution(* coder.rdf.mybatis.study.service.*.*(..))")
public void after(JoinPoint joinPoint){
Object[] args = joinPoint.getArgs();
String name = joinPoint.getSignature().getName();
System.out.println("方法后****切面方法**"+name+"***"+ Arrays.toString(args));
}
@AfterReturning(value="execution(* coder.rdf.mybatis.study.service.*.*(..))" ,returning = "result")
public void afterRunning(JoinPoint joinPoint,Object result){
Object[] args = joinPoint.getArgs();
String name = joinPoint.getSignature().getName();
System.out.println("方法反回后****切面方法**"+name+"***"+ Arrays.toString(args)+"***"+result);
}
@Around(value="execution(* coder.rdf.mybatis.study.service.*.*(..))")
public Object rounding(ProceedingJoinPoint joinPoint) throws Throwable {
long start = Time.now();
System.out.println("环绕方法开始****");
Object proceed = null;
try {
Object[] args = joinPoint.getArgs();
proceed = joinPoint.proceed(args);
} catch (Throwable throwable) {
throw new Throwable("方法调用失败");
}
System.out.println("环绕方法结束****");
long end = Time.now();
System.out.println("****方法执行时间**"+(start-end));
return proceed;
}

@AfterThrowing(value = "execution (* coder.rdf.mybatis.study.service.*.*(..))", throwing = "e")
public void throwException(JoinPoint joinPoint, Exception e) {
String methodName = joinPoint.getSignature().getName();
System.out.println("异常方法调用:" + methodName + " 异常信息" + e);
}
}

springboot使用aspectJ的更多相关文章

  1. 梳理一下我理解的aop

    在看了很多网上的资料和记录之后,我大概捋了下SpringAOP的各种阶段: 基本的advice编程,利用ProxyFactory拿代理类 利用spring把ProxyFactory,advice等be ...

  2. aop详解与实战

    1. 什么是AOP aop:面向切面编程.采用横向机制. oop:面向对象编程.采用纵向机制. AOP,面向切面编程.就是通过某个切入点(比如方法开始.结束)向某个切面(被切的对象)切入环绕通知(需要 ...

  3. java注解@Transactional事务类内调用不生效问题及解决办法

    @Transactional 内部调用例子 在 Spring 的 AOP 代理下,只有目标方法由外部调用,目标方法才由 Spring 生成的代理对象来管理,这会造成自调用问题.若同一类中的其他没有@T ...

  4. SpringBoot下使用AspectJ(CTW)下不能注入SpringIOC容器中的Bean

    SpringBoot下使用AspectJ(CTW)下不能注入SpringIOC容器中的Bean 在SpringBoot中开发AspectJ时,使用CTW的方式来织入代码,由于采用这种形式,切面Bean ...

  5. SpringBoot实例

    7player 7号球员 -- Show Time !跳至内容 首发 左边锋 技术流 外援 教练 7号 基于SpringBoot + Mybatis实现SpringMVC Web项目[原创] 目录 [ ...

  6. 第九章 springboot + mybatis + 多数据源 (AOP实现)

    在第八章 springboot + mybatis + 多数据源代码的基础上,做两点修改 1.ShopDao package com.xxx.firstboot.dao; import org.spr ...

  7. 【spring-boot】spring aop 面向切面编程初接触--切点表达式

    众所周知,spring最核心的两个功能是aop和ioc,即面向切面,控制反转.这里我们探讨一下如何使用spring aop. 1.何为aop aop全称Aspect Oriented Programm ...

  8. Springboot基础篇

    Springboot可以说是当前最火的java框架了,非常适合于"微服务"思路的开发,大幅缩短软件开发周期. 概念 过去Spring充满了配置bean的xml文件,随着spring ...

  9. SpringBoot 注解事务声明式事务

    转载请注明: http://www.cnblogs.com/guozp/articles/7446477.html springboot 对新人来说可能上手比springmvc要快,但是对于各位从sp ...

随机推荐

  1. MindSpore手写数字识别初体验,深度学习也没那么神秘嘛

    摘要:想了解深度学习却又无从下手,不如从手写数字识别模型训练开始吧! 深度学习作为机器学习分支之一,应用日益广泛.语音识别.自动机器翻译.即时视觉翻译.刷脸支付.人脸考勤--不知不觉,深度学习已经渗入 ...

  2. Java安全之JNI绕过RASP

    Java安全之JNI绕过RASP 0x00 前言 前面一直想看该JNI的相关内容,但是发现JNI的资料还是偏少.后面发现JNI在安全中应用非常的微妙,有意思. 0x01 JNI概述 JNI的全称叫做( ...

  3. LeetCode 029 Divide Two Integers

    题目要求:Divide Two Integers Divide two integers without using multiplication, division and mod operator ...

  4. 【原创】Linux虚拟化KVM-Qemu分析(七)之timer虚拟化

    背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: KVM版本:5.9 ...

  5. (十八)面向流水线的设计:CPU的一心多用

    一.单指令周期       由前可知,一条CPU指令的执行有三个步骤:指令读取.指令译码.指令执行.由于这个过程受CPU时钟的控制,如果我们将这个过程安排在一个CPU时钟周期内执行,这种设计思路就叫单 ...

  6. Python(Python+Qt)学习随笔:使用xlwings新建Execl文件和sheet的方法

    在<Python学习随笔:使用xlwings读取和操作Execl文件>介绍了使用xlwings读取和操作Execl文件的方法,但老猿这两天写个例子使用时,发现使用该文的方法无法新建EXCE ...

  7. js原生方法map实现

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 题解-NOI2003 智破连环阵

    题面 NOI2003 智破连环阵 有 \(m\) 个靶子 \((ax_j,ay_j)\) 和 \(n\) 个箭塔 \((bx_i,by_i)\).每个箭塔可以射中距离在 \(k\) 以内的靶子.第 \ ...

  9. 笨方法学python笔记

    编程是什么 编程就是通过输出一种语言给计算机"听",命令其去执行相应的操作. 我们称我们给计算机下达的命令称为指令.一般说程序就是有多个指令构成的. 计算机需要使用非常多的电路来实 ...

  10. 题解-洛谷P4139 上帝与集合的正确用法

    上帝与集合的正确用法 \(T\) 组数据,每次给定 \(p\),求 \[\left(2^{\left(2^{\left(2^{\cdots}\right)}\right)}\right)\bmod p ...