-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Kek opened SPR-5453 and commented
I have a situation, when I need to guarantie that my Aspect is the last one in the invocation chain. So I annotated the Aspect class with @Order
(Ordered.LOWEST_PRECEDENCE). But this does not work, after some hours of debuging I found, that the problem is in BeanFactoryAspectInstanceFactory.getOrder() method, because all other aspects, without @Order
and without "implements Ordered", have the default order value Ordered.LOWEST_PRECEDENCE.
public int getOrder() {
Class type = this.beanFactory.getType(this.name);
if (type != null) {
if (Ordered.class.isAssignableFrom(type) && this.beanFactory.isSingleton(this.name)) {
return ((Ordered) this.beanFactory.getBean(this.name)).getOrder();
}
Order order = (Order) type.getAnnotation(Order.class);
if (order != null) {
return order.value();
}
}
return Ordered.LOWEST_PRECEDENCE;
}
So it is not possible to create some Aspect with lower precedence than the "not ordered" aspect. In my opinion, the default order value should be something between Ordered.LOWEST_PRECEDENCE and Ordered.HIGHEST_PRECEDENCE like Ordered.DEFAULT_PRECEDENCE=0. It is the same idea as in java.lang.Thred.priority, there is MIN_PRIORITY, NORM_PRIORITY, MAX_PRIORITY. But I know, there will be problem with backward compatibility.
I didn't find any way how to change the BeanFactoryAspectInstanceFactory implementation for my aspectj-autoproxy configuration, so my current solution is to define @Order
on all Aspects.
Thank's for any other better solution.
Affects: 2.5.6
2 votes, 4 watchers