基础文献

    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. Java学习——用户电话输入显示

    编写程序:在窗口中添加组件,产生如下图形化界面:当用户输入用户名和电话后,点击显示按钮后,按下图格式显示. package cys; import java.awt.*; import java.aw ...

  2. 读取 Excel 之 Epplus

    using (OpenFileDialog fd = new OpenFileDialog()) { fd.Filter = "Excel 2007文件(*.xlsx)|*.xlsx|所有文 ...

  3. Python twilio发短信实践

    twilio注册地址   注册的时候可能会报错   最好是*** -->注册-->注册完毕后代码运行是不需要***的 https://www.twilio.com/console 需要pi ...

  4. UTC时间和普通时间的区别

            UTC时间 [root@openstack01 ~]# timedatectl Local time: Sat 2018-08-18 23:04:24 CST Universal ti ...

  5. Zabbix系统中的历史数据和趋势数据

    原文:http://blog.chinaunix.net/uid-9411004-id-4139807.html 或许读者还记得,我们在介绍如何创建一个监控项目时,我们介绍过在“配置项目”表单页面上有 ...

  6. 矩阵半正定: positive semidefinite

    具体定义:https://en.wikipedia.org/wiki/Positive-definite_matrix

  7. 10 Skills Every SharePoint Developer Needs

    10 Skills Every SharePoint Developer Needs(原文) This blog post guides you through the essential skill ...

  8. POJ 多项式加法

    题解: 采用顺序表.考虑到题目中没有规定指数上界,为避免RE,拟不采用数组.参考了http://blog.csdn.net/inlovecy/article/details/15208473后,最终采 ...

  9. HBase配置性能调优

    因官方Book Performance Tuning部分章节没有按配置项进行索引,不能达到快速查阅的效果.所以我以配置项驱动,重新整理了原文,并补充一些自己的理解,如有错误,欢迎指正. 配置优化 zo ...

  10. centos 7 安装sqoop 1.4.7

    1. 下载sqoop1.4.7 cd /home/workspace wget https://mirrors.tuna.tsinghua.edu.cn/apache/sqoop/1.4.7/sqoo ...