就是@Before @Around @AfterReturning @AfterThrowing这几个标签的属性可以放到方法参数里面获取

例子

//正常操作
@Around("service()")
public void doAround(JoinPoint joinPoint) throws Throwable {
// 接收到请求,记录请求内容
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
// 记录下请求内容
System.out.println("URL : " + request.getRequestURL().toString());
System.out.println("HTTP_METHOD : " + request.getMethod());
System.out.println("IP : " + request.getRemoteAddr());
System.out.println("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
System.out.println("ARGS : " + Arrays.toString(joinPoint.getArgs()));
} //获取annotation
@Around("@annotation(log)")
public Object around(ProceedingJoinPoint pjp, Log log) {
//获取注解里的值
System.out.println("annotation around:" + log.description());
try {
return pjp.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
return null;
}
} //获取异常
@AfterThrowing(pointcut = "within(com.lgp.aop..*) && @annotation(log)", throwing = "ex")
public void addAfterThrowingLogger(JoinPoint joinPoint, Log log, Exception ex) {
logger.error("执行 " + log.description() + " 异常,error={}", ex.getMessage(), ex);
}
 

注意,参数名字应该一致。

Spring AOP的增强处理的更多相关文章

  1. Spring aop——前置增强和后置增强 使用注解Aspect和非侵入式配置

    AspectJ是一个面向切面的框架,它扩展了java语言,定义了AOP语法,能够在编译期提供代码的织入,所以它有一个专门的编译器用来生成遵守字节码字节编码规范的Class文件 确保使用jdk为5.0以 ...

  2. Spring AOP 创建增强类

    AOP联盟为增强定义了org.aopalliance.aop.Advice接口,Spring支持5种类型的增强:     1)前置增强:org.springframework.aop.BeforeAd ...

  3. Spring AOP 切面编程的方法

    spring aop的使用分为两种,一种是使用注解来实现,一种是使用配置文件来实现. 先来简单的介绍一下这两种方法的实现,接下来详细的介绍各处的知识点便于查阅.目录如下: 1.基于注解实现spring ...

  4. Spring Aop 动态代理失效分析

    1. Spring Aop 原理 Spring Aop 通过动态代理创建代理对象,在调用代理对象方法前后做增强. 2. Transactional, Async 注解失效? 当在动态代理方法中调用当前 ...

  5. Spring AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)

    1.我所知道的AOP 初看起来,上来就是一大堆的术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充等等.一下让你不知所措,心想着:管不得很多人都和我说AOP多难多难.当我看进去以后, ...

  6. AOP执行增强-Spring 源码系列(5)

    AOP增强实现-Spring 源码系列(5) 目录: Ioc容器beanDefinition-Spring 源码(1) Ioc容器依赖注入-Spring 源码(2) Ioc容器BeanPostProc ...

  7. spring---aop(9)---Spring AOP中引入增强

    写在前面 Spring将introduction通知看作一种特殊类型的拦截通知.用Spring的行话来讲,对方法的增强叫做Wearing(织入),而对类的增强叫introduction(引入).Int ...

  8. Spring AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)(转)

    1.我所知道的AOP 初看起来,上来就是一大堆的术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充等等.一下让你不知所措,心想着:管不得很多人都和我说AOP多难多难.当我看进去以后, ...

  9. Spring AOP获取不了增强类(额外方法)或无法通过getBean()获取对象

    Spring AOP获取不了增强类(额外方法)和无法通过getBean()获取对象 今天在学习AOP发现一个小问题 Spring AOP获取不了额外方法,左思右想发现是接口上出了问题 先上代码 获取不 ...

随机推荐

  1. PID控制及整定算法

    一.PID控制算法 PID是比例.积分.微分的简称,PID控制的难点不是编程,而是控制器的参数整定.参数整定的关键是正确地理解各参数的物理意义,PID 控制的原理可以用人对炉温的手动控制来理解.阅读本 ...

  2. 关于hist

    """ Demo of the histogram (hist) function with a few features. In addition to the bas ...

  3. 串口发送Hex数组

    void MainWindow::String2Hex(QString str, QByteArray &senddata) { int hexdata,lowhexdata; ; int l ...

  4. eclipse 远程操作HIVE

    首先启动HiveServer hive --service hiveserver 10000 & 创建工程 引入包: 代码(简单的查询): package com.hive.jdbc; imp ...

  5. R: which(查询位置)、%in% (是否存在)、ifelse(判断是否):

    ################################################### 问题:ifelse.which.%in%    18.4.27 解决方案: > x < ...

  6. C#中类和结构体

    结构体 类 自己的一些理解 首先结构中不能给字段赋值  而类可以 结构调用方法是  例如 People p1: 类的调用方法是  Book b =new Book(): 1.类能够实例化 而结构不可以 ...

  7. 【C#】VS2017 winform 打包

    首先要在想要打包的项目下创建一个新的项目, 创建好setup项目,之后点击属性,去修改打包软件的名字,ProductName....可以选填 到此已经创建好了setup工程了,那么下面开始将要打包的d ...

  8. 牛客网小白月赛6H(最小生成树【克鲁斯卡尔】)

    #include<bits/stdc++.h>using namespace std;long long sum=0;struct node{    int a,b,len;}road[5 ...

  9. c++第四次实验2

    Part 1 车辆基本信息管理 1.代码 #include<iostream> using namespace std; #include"car.h" #includ ...

  10. Unable to round-trip http request to upstream: EOF问题

    Unable to round-trip http request to upstream: EOF, 今天我用的phpstudy环境中的网站页面忽然打不开了,报错“Unable to round-t ...