Aop 基础
基础文献
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 基础的更多相关文章
- [Spring框架]Spring AOP基础入门总结二:Spring基于AspectJ的AOP的开发.
前言: 在上一篇中: [Spring框架]Spring AOP基础入门总结一. 中 我们已经知道了一个Spring AOP程序是如何开发的, 在这里呢我们将基于AspectJ来进行AOP 的总结和学习 ...
- [Spring框架]Spring AOP基础入门总结一.
前言:前面已经有两篇文章讲了Spring IOC/DI 以及 使用xml和注解两种方法开发的案例, 下面就来梳理一下Spring的另一核心AOP. 一, 什么是AOP 在软件业,AOP为Aspect ...
- CgLib动态代理学习【Spring AOP基础之一】
如果不了解JDK中proxy动态代理机制的可以先查看上篇文章的内容:Java动态代理学习[Spring AOP基础之一] 由于Java动态代理Proxy.newProxyInstance()的时候会发 ...
- Spring笔记:AOP基础
Spring笔记:AOP基础 AOP 引入AOP 面向对象的开发过程中,我们对软件开发进行抽象.分割成各个模块或对象.例如,我们对API抽象成三个模块,Controller.Service.Comma ...
- 15Spring AOP基础
为什么需要AOP? 先来看一段代码: package com.cn.spring.aop.helloworld; //加减乘除的接口类 public interface ArithmeticCalcu ...
- (spring-第19回【AOP基础篇】)基于AspectJ和Schema的AOP
基于AspectJ就是基于@AspectJ注解,基于Schema就是全部依靠配置文件.那么首先要了解Java注解. Java注解初探 在JDK5.0中,我们可以自定义标签,并通过Java语言的反射机制 ...
- (spring-第16回【AOP基础篇】)基本概念
AOP(Aspect Oriented Programing),面向切面方程.介绍具体定义前,先看一个例子: package com.baobaotao.concept; public class F ...
- 开涛spring3(6.1) - AOP 之 6.1 AOP基础
6.1.1 AOP是什么 考虑这样一个问题:需要对系统中的某些业务做日志记录,比如支付系统中的支付业务需要记录支付相关日志,对于支付系统可能相当复杂,比如可能有自己的支付系统,也可能引入第三方支付平 ...
- 【AOP】Spring AOP基础 + 实践 完整记录
Spring AOP的基础概念 ============================================================= AOP(Aspect-Oriented Pr ...
随机推荐
- Mongod服务器安装
第一步下载mongodb 目前最新版本:3.4.4 第二步安装vc_redist.x64 服务器安装可能会需要到,如果没有出现以下错误不需要安装 --------------------------- ...
- C#、AE开发入门之打开CAD文件并显示
加载CAD文件稍显复杂一些,总体还是和前面基本类似 private void button3_Click(object sender, EventArgs e) { axMapControl1.Cle ...
- kafka产生的数据通过Flume存到HDFS中
试验目标: 把kafka的生产者发出的数据流经由Flume放到HDFS来存储. 试验环境: java:1.8 kafka:2.11 flume:1.6 hadoop:2.8.5 试验流程: 1.进入z ...
- WordPress更换主题空白问题
刚才尝试着更换了一个主题,后来发现预览主页的时候是一片空白.查了很多资料,有说是index.php的权限问题,有说是插件问题,有说是UTL-8编码的问题,我都试过了,发现都不行,后来仔细研究了一下,发 ...
- navicat for mysql 最简便的破解方法
Navicat 破解工具 1.安装Navicat软件 安装成功之后进行破解. 然后选择刚刚安装的Navicat安装路径下找到navicat.exe文件,点击选择即可激活 成功. (注意此步骤解析的是 ...
- [UE4]小地图UI设计
一.新建一个名为TestMiniMap的UserWidget用来使用小地图StaticMiniMap. 二.在左侧“User Created”面板中可以看到除自身以外的其他所有用户创建的UserWid ...
- [UE4]加入音效
- Android 中Jackson的简单使用
第一步:下载Jackson的jar包http://pan.baidu.com/s/1qXHwtQ0 第二步:在gradle中导入jar包 第三步:创建ObjectMapper对象的单例 Jackson ...
- vue 动态路由 Get传值
main.js //2.配置路由 注意:名字 const routes = [ { path: '/home', component: Home }, { path: '/news', compone ...
- Css学习(三)
1 行高 ◆浏览器默认文字大小 浏览器默认文字大小:16px 行高:是基线与基线之间的距离 行高=文字高度+上下边距 一行文字行高和父元素高度一致的时候,垂直居中显示. 行高的单位 总结:单位除了像素 ...