基础文献

    https://blog.csdn.net/abcd898989/article/details/50809321

简单Demo配置

  pom.xml

     <!-- AOP -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

  主类上加上Aop注解

//Aop代理
@EnableAspectJAutoProxy(proxyTargetClass=true, exposeProxy = true)
package com.cjcx.pay.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component; import java.util.Arrays; @Slf4j
@Aspect
@Component
public class ServiceMonitor { /**
* 前置通知:目标方法执行之前执行以下方法体的内容
*
* @param joinPoint
*/
@Before("execution(* com..*Service.demo(..))")
public void Before(JoinPoint joinPoint) {
log.info("Before Completed: " + joinPoint);
log.info("joinPoint toString(): " + joinPoint.toString()); Object obj = joinPoint.getThis();
log.info("joinPoint getThis: " + obj); Object target = joinPoint.getTarget();
log.info("joinPoint getTarget: " + target); Signature signature = joinPoint.getSignature();
log.info("joinPoint getSignature: " + signature.toString());
log.info("joinPoint signature getName: " + signature.getName());
log.info("joinPoint signature getModifiers: " + signature.getModifiers());
log.info("joinPoint signature getDeclaringType: " + signature.getDeclaringType());
log.info("joinPoint signature getDeclaringTypeName: " + signature.getDeclaringTypeName());
log.info("joinPoint getArgs: " + Arrays.asList(joinPoint.getArgs()));
} /**
* 后置通知:目标方法执行之后执行以下方法体的内容,不管是否发生异常。
*
* @param joinPoint
*/
@After("execution(* com..*Service.demo(..))")
public void After(JoinPoint joinPoint) {
log.info("After Completed: " + joinPoint);
} /**
* 返回通知:目标方法正常执行完毕时执行以下代码
*
* @param joinPoint
*/
@AfterReturning(value = "execution(* com..*Service.demo(..))", returning = "result")
public void AfterReturning(JoinPoint joinPoint, Object result) {
log.info("AfterReturning Completed: " + joinPoint);
log.info("AfterReturning returning result" + result);
} /**
* 异常通知:目标方法发生异常的时候执行以下代码
*
* @param joinPoint
*/
@AfterThrowing(value = "execution(* com..*Service.demo(..))", throwing = "e")
public void AfterThrowing(JoinPoint joinPoint, Exception e) {
log.info("AfterThrowing Completed: " + joinPoint);
log.info("AfterThrowing Exception: " + e.getMessage());
} /**
* 环绕通知:目标方法执行前后分别执行一些代码,发生异常的时候执行另外一些代码
*
* @param jp
*/
/*@Around("execution(* com..*Service.demo(..))")
public Object Around(ProceedingJoinPoint jp) {
log.info("Around Completed: " + jp);
String methodName = jp.getSignature().getName();
Object result = null;
try {
System.out.println("【环绕通知中的--->前置通知】:the method 【" + methodName + "】 begins with " + Arrays.asList(jp.getArgs()));
//执行目标方法
result = jp.proceed();
System.out.println("【环绕通知中的--->返回通知】:the method 【" + methodName + "】 ends with " + result);
} catch (Throwable e) {
System.out.println("【环绕通知中的--->异常通知】:the method 【" + methodName + "】 occurs exception " + e);
} System.out.println("【环绕通知中的--->后置通知】:-----------------end.----------------------");
return result;
}*/ }

Aop 基础的更多相关文章

  1. [Spring框架]Spring AOP基础入门总结二:Spring基于AspectJ的AOP的开发.

    前言: 在上一篇中: [Spring框架]Spring AOP基础入门总结一. 中 我们已经知道了一个Spring AOP程序是如何开发的, 在这里呢我们将基于AspectJ来进行AOP 的总结和学习 ...

  2. [Spring框架]Spring AOP基础入门总结一.

    前言:前面已经有两篇文章讲了Spring IOC/DI 以及 使用xml和注解两种方法开发的案例, 下面就来梳理一下Spring的另一核心AOP. 一, 什么是AOP 在软件业,AOP为Aspect ...

  3. CgLib动态代理学习【Spring AOP基础之一】

    如果不了解JDK中proxy动态代理机制的可以先查看上篇文章的内容:Java动态代理学习[Spring AOP基础之一] 由于Java动态代理Proxy.newProxyInstance()的时候会发 ...

  4. Spring笔记:AOP基础

    Spring笔记:AOP基础 AOP 引入AOP 面向对象的开发过程中,我们对软件开发进行抽象.分割成各个模块或对象.例如,我们对API抽象成三个模块,Controller.Service.Comma ...

  5. 15Spring AOP基础

    为什么需要AOP? 先来看一段代码: package com.cn.spring.aop.helloworld; //加减乘除的接口类 public interface ArithmeticCalcu ...

  6. (spring-第19回【AOP基础篇】)基于AspectJ和Schema的AOP

    基于AspectJ就是基于@AspectJ注解,基于Schema就是全部依靠配置文件.那么首先要了解Java注解. Java注解初探 在JDK5.0中,我们可以自定义标签,并通过Java语言的反射机制 ...

  7. (spring-第16回【AOP基础篇】)基本概念

    AOP(Aspect Oriented Programing),面向切面方程.介绍具体定义前,先看一个例子: package com.baobaotao.concept; public class F ...

  8. 开涛spring3(6.1) - AOP 之 6.1 AOP基础

    6.1.1  AOP是什么 考虑这样一个问题:需要对系统中的某些业务做日志记录,比如支付系统中的支付业务需要记录支付相关日志,对于支付系统可能相当复杂,比如可能有自己的支付系统,也可能引入第三方支付平 ...

  9. 【AOP】Spring AOP基础 + 实践 完整记录

    Spring AOP的基础概念 ============================================================= AOP(Aspect-Oriented Pr ...

随机推荐

  1. 怎么把PNG图的位深度24位变成32位

    在PS里把图片的变成层模式,不透明度设置成99%,在保存成PNG

  2. css中背景的应用

    浏览器默认的字体大小是 font-size:16px; 谷歌最小的是10px 其他浏览器是12px 通配符选择器 *   “*”的意思是代表所有的标签 回到正题 background   背景 他的几 ...

  3. Zabbix 创建监控项目

    #1 #2 [root@nod01 zabbix_agentd.d]# pwd/etc/zabbix/zabbix_agentd.d 新建文件nod.conf [root@nod01 zabbix_a ...

  4. keystone认证服务

    实验操作平台:OpenStack单节点操作 一.相关概念 1.认证(authentication) 认证是确认允许一个用户访问的进程 2.证书(credentials) 用于确认用户身份的数据 3.令 ...

  5. php安装imagemagick扩展 常见问题与解决方案(win平台)

    1.写在前面 1-1.ImageMagick介绍 ImageMagick是一套功能强大.稳定而且开源的工具集和开发包,可以用来读.写和处理超过89种基本格式的图片文件,包括流行的TIFF.JPEG.G ...

  6. NT平台ADSL拨号连接密码恢复原理

    NT平台拨号连接密码恢复原理 创建时间:2004-11-08 更新时间:2004-11-12文章属性:原创文章提交:eyas (eyas_at_xfocus.org)NT平台拨号连接密码恢复原理Aut ...

  7. 用微信小程序连接WordPress网站

    随着微信小程序的功能越来越强,特别对个人开发者的开放,让个人开发者有机会尝试微信小程序.如果你有自己的个人网站,就可以把个人网站搬到微信小程序里,通过小程序直接访问网站的内容. 要想微信小程序可以获取 ...

  8. JavaWeb中四大域对象的作用范围

    JavaWeb的四大作用域为:PageContext,ServletRequest,HttpSession,ServletContext: PageContext域:作用范围是整个JSP页面,是四大作 ...

  9. 《Linux性能及调优指南》第二章:监控和基准工具2.1-2.2

    翻译:飞哥 (http://hi.baidu.com/imlidapeng) 版权所有,尊重他人劳动成果,转载时请注明作者和原始出处及本声明. 原文名称:<Linux Performance a ...

  10. 零基础学习python_文件(28-30课)

    本人小白一枚,随着现在对测试要求越来越高,动不动就要去会一门编程语言,没办法只能学习学习Python,今天看到几个月前还是菜鸟的人突然就已经能使用Python写简单系统了,没办法,虽然之前也简单学习过 ...