aspectj - Spring aspect ordering -
what order of invocations on "way in" if have 3 aspects like:
@order(ordered.highest_precedence) public class aspect1 public class aspect2 @order(ordered.lowest_precedence) public class aspect3
so aspect2 doesn't have order annotation.
it clear aspect1 invoked before aspect3, mean aspect2 invoked in between ?
from official javadoc @order:
annotation defines ordering. value optional, , represents order value defined in ordered interface. lower values have higher priority. default value ordered.lowest_precedence, indicating lowest priority (losing other specified order value).
this means aspect2
have value of ordered.lowest_precedence
, integer.max_value
. don't think there way of being 100% sure invoked before aspect3
- believe depends on order of component scan.
if want sure, can put in exact values:
@order(1) public class aspect1 {...} @order(2) public class aspect2 {...} @order(3) public class aspect3 {...}
or put value between integer.min_value
, integer.max_value
on aspect2
:
@order(0) public class aspect2 {...}
here test confirms this:
@runwith(springjunit4classrunner.class) @springapplicationconfiguration(classes = {class1.class, class3.class, class2.class}) public class testtest { public static interface test {} @order(ordered.highest_precedence) @component public static class class1 implements test {} @order @component public static class class2 implements test {} @order(ordered.lowest_precedence) @component public static class class3 implements test {} @autowired list<test> list; @test public void test() { system.out.println("list: " + list); } }
this output:
list: [testtest$class1@d21a74c, testtest$class3@6e509ffa, testtest$class2@2898ac89]
but if change order of classes 2
, 3
in @springapplicationconfiguration
, class2
invoked second.
Comments
Post a Comment