转自:http://blog.csdn.net/rainbow702/article/details/52185827

情况一: 一个方法只被一个Aspect类拦截

正常情况: 


异常情况: 

情况二: 同一个方法被多个Aspect类拦截

方法有两种:

  • 实现org.springframework.core.Ordered接口,实现它的getOrder()方法
  • 给aspect添加@Order注解,该注解全称为:org.springframework.core.annotation.Order
@Order(5)
@Component
@Aspect
public class Aspect1 {
// ...
} @Order(6)
@Component
@Aspect
public class Aspect2 {
// ...
}

注意点

  • 如果在同一个 aspect 类中,针对同一个 pointcut,定义了两个相同的 advice(比如,定义了两个 @Before),那么这两个 advice 的执行顺序是无法确定的,哪怕你给这两个 advice 添加了 @Order 这个注解,也不行。这点切记。

  • 对于@Around这个advice,不管它有没有返回值,但是必须要方法内部,调用一下 pjp.proceed();否则,Controller 中的接口将没有机会被执行,从而也导致了 @Before这个advice不会被触发。

转 Spring AOP @Before @Around @After 等 advice 的执行顺序的更多相关文章

  1. Spring AOP @Before @Around @After 等 advice 的执行顺序

    用过spring框架进行开发的人,多多少少会使用过它的AOP功能,都知道有@Before.@Around和@After等advice.最近,为了实现项目中的输出日志和权限控制这两个需求,我也使用到了A ...

  2. spring Aop切面中的@Before @Around等执行顺序与请求参数统一解码

    1.背景 在实际开发中,我可能会对请求接口做统一日志输出,或者统一参数解析,验签,统一响应加密等,通常会用到aop,实际案例如下 2.代码 package com.qianxingniwo.log; ...

  3. Spring学习十五----------Spring AOP API的Pointcut、advice及 ProxyFactoryBean相关内容

    © 版权声明:本文为博主原创文章,转载请注明出处 实例: 1.项目结构 2.pom.xml <project xmlns="http://maven.apache.org/POM/4. ...

  4. Spring课程 Spring入门篇 6-1 Spring AOP API的PointCut、advice的概念及应用

    本节主要是模拟spring aop 的过程. 实现spring aop的过程 这一节老师虽然说是以后在工作中不常用这些api,实际上了解还是有好处的, 我们可以从中模拟一下spring aop的过程. ...

  5. Spring Aop(五)——给Advice传参

    转发:https://www.iteye.com/blog/elim-2395337 5 给Advice传递参数 Advice除了可以接收JoinPoint(非Around Advice)或Proce ...

  6. 正确理解Spring AOP中的Around advice

    Spring AOP中,有Before advice和After advice,这两个advice从字面上就可以很容易理解,但是Around advice就有点麻烦了. 乍一看好像是Before ad ...

  7. Spring AOP 中 advice 的四种类型 before after throwing advice around

    spring  AOP(Aspect-oriented programming) 是用于切面编程,简单的来说:AOP相当于一个拦截器,去拦截一些处理,例如:当一个方法执行的时候,Spring 能够拦截 ...

  8. [转]彻底征服 Spring AOP 之 理论篇

    基本知识 其实, 接触了这么久的 AOP, 我感觉, AOP 给人难以理解的一个关键点是它的概念比较多, 而且坑爹的是, 这些概念经过了中文翻译后, 变得面目全非, 相同的一个术语, 在不同的翻译下, ...

  9. Spring AOP基本概念

    Spring AOP基本概念 目录 Spring AOP定义 AOP基本术语 通知类型 AOP定义 AOP基本术语 切面( Aspect ):一个能横切多个对象的模块化的关注点.对Spring AOP ...

随机推荐

  1. Androoid studio 2.3 AAPT err(Facade for 596378712): \\?\C:\Users\中文文件夹\.android\build-cache

    错误如下: Error:Some file crunching failed, see logs for details Error:Execution failed for task ':app:m ...

  2. Non-standard evaluation, how tidy eval builds on base R

    As with many aspects of the tidyverse, its non-standard evaluation (NSE) implementation is not somet ...

  3. bootstrap全局css样式

    以下从官网抄来的,感觉还是很实用的,运用得好,灵活运用,非常方便快捷,能大大提高开发效率,也为调整不同尺寸的屏幕节省了时间. hidden-xs @media (max-width: 767px){ ...

  4. Bootstrap-Plugin:轮播(Carousel)插件

    ylbtech-Bootstrap-Plugin:轮播(Carousel)插件 1.返回顶部 1. Bootstrap 轮播(Carousel)插件 Bootstrap 轮播(Carousel)插件是 ...

  5. 1027代码审计平台 1-sonar scanner

    1.代码审计 1.1综合性的代码分析平台 sonar支持自定义规则,较多的公司使用 360火线 1.2IDE辅助功能 Xcode.Android studio 阿里巴巴Java开发手机ide插件支持 ...

  6. WebAPI认证与授权

    Web APi之认证(Authentication)及授权(Authorization)[一](十二) http://www.cnblogs.com/CreateMyself/p/4856133.ht ...

  7. python socket 详细介绍

    Python 提供了两个基本的 socket 模块. 第一个是 Socket,它提供了标准的 BSD Sockets API. 第二个是 SocketServer, 它提供了服务器中心类,可以简化网络 ...

  8. Solr分组聚合查询之Facet

    摘要: Solr的分组聚合是一个笼统的概念,目的就是把查询结果做分类,有多种方式可以做到很类似的结果.也正是由于它们的不同表现,可以适合于多种场景. 何为Facet Facet是一种手段,用来将搜索结 ...

  9. Curl Methods

    curl -H "Content-Type:application/json" -H "Authorization token:d0a92f4c29b448c010b59 ...

  10. PyDev for eclipse 插件下载地址

    PyDev for eclipse 插件下载地址http://sourceforge.net/projects/pydev/files/pydev/python解释器以及python类库下载地址htt ...