The order of the advices inside the same aspect in Aspectj

Tags: ,



How do you determine the order of advices inside the same aspect when you have multiple arounds, befores and afters and all of them “point” to the same pointcut? I have read the aspectj documentation, but i just can’t get it.

Answer

You claim to have read the AspectJ manual. Why don’t you just link to the corresponding pages you have read? My recommendation is to read the section about advice precedence which is quite clear and precise, yet concise and can be read in two minutes. Of course, you should re-read in order to really understand it because the information there is quite compressed. It should answer all your questions, though.

You can test your understanding by writing a little sample program + aspect with a bunch of different advices printing the joinpoint to the console. Then before(!) running the sample program you should write down or at least imagine what the output will look like. Finally, run the program and check your understanding.

If afterwards you still do not understand or think that the AspectJ manual is unclear, please edit your question, post the complete(!) sample program + aspect + console log and ask a concrete question about which part you do not understand.

This is how you learn best and this is how you ask questions here best.


Update: I just remembered that 4 years ago I answered a much more concrete and detailed question than this one, honouring it with a detailed, comprehensive answer too because it deserved one. You may want to read it. It explains in much detail what the AspectJ manual explains in a more abstract way.



Source: stackoverflow