Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9438

Mixed ordering of @Before and @After advices does not work

    Details

      Description

      Ordering is not applied when there are in place both @After and @Before advices.

      In this case the order number is silently ignored because of this extra code:
      https://github.com/SpringSource/spring-framework/blob/master/spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJPrecedenceComparator.java#L93

      Is this error or intention?

      Such limitation is not mentioned in the documentation:
      http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-ataspectj-advice-ordering

      I have a real situation (simplified in attached example) when I have a @Before advice, which is able to throw an Exception, preventing the target method to be called. I also have one @After advice which needs to be called with no matter if the Exception was thrown by @Before advice or not. So I need to set ordering of aspects: higher precedence for the @After advice and lower precedence for the @Before advice. But here comes the problem - ordering is ignored for mixed @After and @Before advices.

      Please see the attached demo project which demonstrates the problem.

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              miso.moravcik Michal Moravcik
              Last updater:
              Michal Moravcik
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 10 weeks, 2 days ago