Advice ordering

Now we know how to write advice and how to create Aspect. Let's see how advice ordering can help us to prioritize our advice when we have multiple advice on the same join point:

  • Let's say we wrote two before or after advice in different aspects and both want to run at the same join point. In this case, the order of execution of the advice would be based on the which aspect comes first in the execution of classes. To avoid this and apply our advice one after the other, Spring provides a way to specify the order of execution by either implementing the Ordered interface by an aspect or applying the @Order annotation. The lower the value of the order, the higher the precedence.
  • While declaring an advice, always use the least powerful form of advice; for example, if a simple before advice would achieve our requirement, we should not use the around advice.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset