为什么after会在afterReturn之前?

来源:5-5 Advice应用(下)

追逐繁星0

2016-07-23 20:31

老师,你好,为什么本节视频的after会在afterReturn之前?参考本节(5-5)的05:08(5分08秒)处。

而上节视频的after会在afterReturn之后,参考上节(5-4)的13:36(13分36秒)处。

写回答 关注

6回答

  • qq_千年jack
    2018-08-12 16:28:00

    使用注解时跟配置顺序无关,跟around无关。

    使用配置进行编译时跟around有关,跟配置顺序也有关系。

  • 精慕门1546425
    2018-07-20 10:47:51

    Spring官方的说法是,在同一个切面内,同类型(前/后)的通知顺序是不确定的。因为通过反射确定类中生命(这句话的意思,我也不理解)。

    见官方文档说明(同时给出了排序的建议):

    When two pieces of advice defined in the same aspect both need to run at the same join point, the ordering is undefined (since there is no way to retrieve the declaration order via reflection for javac-compiled classes). Consider collapsing such advice methods into one advice method per join point in each aspect class, or refactor the pieces of advice into separate aspect classes - which can be ordered at the aspect level.

    精慕门154...

    确定类中生命=确定类中声明顺序

    2018-07-20 10:51:01

    共 1 条回复 >

  • 稻子凡
    2017-09-04 16:49:01

    我认为,after是在目标方法的执行结束的前一刻产生效果,而afterreturning是在目标方法已经结束时产生效果,所以after才会比afterreturning先输出

    稻子凡

    哈 错了 当有配置around时,after和after-returning的执行顺序和它们在xml文件中配置顺序相反。

    2017-09-04 16:51:15

    共 1 条回复 >

  • qq_幸福客_0
    2017-02-13 14:04:59

    试了一下,跟xml配置顺序没有关系,只跟有没有配置around有关

    qq_幸福客...

    我错了,跟配置顺序还是有关系的

    2017-02-13 14:07:26

    共 1 条回复 >

  • 武zz
    2016-11-10 14:01:18

    当有配置around时,after和after-returning的执行顺序和它们在xml文件中配置顺序相反。

  • 飞侠li
    2016-07-25 21:26:13

    与after和afterReturning的在配置文件的位置有关

    战神无敌冲

    我测试了一下,不是这个原因

    2016-08-15 19:17:30

    共 1 条回复 >

Spring入门篇

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

268773 学习 · 963 问题

查看课程

相似问题