基础文献

    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. IDC:UPS(不间断电源)

    ylbtech-IDC:UPS(不间断电源) UPS(Uninterruptible Power System/Uninterruptible Power Supply),即不间断电源,是将蓄电池(多 ...

  2. opengl 无法定位程序输入点_glutInitWithExit于动态链接库glut32.dll上

    1.问题:opengl 无法定位程序输入点_glutInitWithExit于动态链接库glut32.dll上 2.环境:vc6.0  win7,64位,opengl. 3.解决:将glut32.dl ...

  3. 在HP-UX 11.11用swinstall安装gcc 4.2.3

    agent60 在linux上执行不了,原因是操作系统内核版本不一致,需要重新编译包. file $SHELL 显示  PA-RISC1.1 在HP-UX 11.31 PA-RISC1.1 版本中 编 ...

  4. 点击input触发弹出框的bug

    先点击第一个input建立弹出框,再点击第二个input打开弹出框,操作点击,同时触发了两个input点击事件.主要原因是建立弹出框时绑定了input1的click事件,再次触发时,又再亿次绑定了in ...

  5. Selector空轮询处理(转载)

    https://www.cnblogs.com/my_life/articles/5556939.html Selector空轮询处理 在NIO中通过Selector的轮询当前是否有IO事件,根据JD ...

  6. go语言学习--map类型的切片

    今天在项目中遇到了一个切片的map,记录下map切片的使用 package main import "fmt" func main() { // Version A: items ...

  7. [UE4]非常实用的SizeBox控件

    Desired:表示以期望的实际尺寸显示视图. SizeBox最好作为Child Widget的根节点.(如果SizeBox的父节点是Canvas Panel,SizeBox会变成可拉伸,ChildL ...

  8. Mybatis 系列1-环境搭建

    [Mybatis 系列10-结合源码解析mybatis 执行流程] [Mybatis 系列9-强大的动态sql 语句] [Mybatis 系列8-结合源码解析select.resultMap的用法] ...

  9. Mongodb集群搭建之 Sharding+ Replica Sets集群架构(2)

    参考http://blog.51cto.com/kaliarch/2047358 一.概述 1.1 背景 为解决mongodb在replica set每个从节点上面的数据库均是对数据库的全量拷贝,从节 ...

  10. Vue百度搜索

    <!DOCTYPE html><html lang="en"><head> <meta charset="GBK"&g ...