javax.annotation.Priority alternative to @Order

This commit rationalizes the use of @Order so that the standard
@Priority annotation can be used instead. The handling of both
annotations are now defined in OrderUtils.

This also updates the link to the JavaEE API so that we refer to
JavaEE7 instead of JavaEE6.

Issue: SPR-11639
This commit is contained in:
Stephane Nicoll
2014-04-01 14:30:47 +02:00
parent 5fe8f52c02
commit dcf5f4a6a3
12 changed files with 211 additions and 61 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,8 +19,7 @@ package org.springframework.aop.aspectj.annotation;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.core.annotation.OrderUtils;
import org.springframework.util.ClassUtils;
/**
@@ -110,10 +109,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
if (Ordered.class.isAssignableFrom(type) && this.beanFactory.isSingleton(this.name)) {
return ((Ordered) this.beanFactory.getBean(this.name)).getOrder();
}
Order order = AnnotationUtils.findAnnotation(type, Order.class);
if (order != null) {
return order.value();
}
return OrderUtils.getOrder(type, Ordered.LOWEST_PRECEDENCE);
}
return Ordered.LOWEST_PRECEDENCE;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +18,7 @@ package org.springframework.aop.aspectj.annotation;
import org.springframework.aop.aspectj.SimpleAspectInstanceFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.core.annotation.OrderUtils;
/**
* Implementation of {@link MetadataAwareAspectInstanceFactory} that
@@ -51,20 +50,9 @@ public class SimpleMetadataAwareAspectInstanceFactory extends SimpleAspectInstan
return this.metadata;
}
/**
* Determine a fallback order for the case that the aspect instance
* does not express an instance-specific order through implementing
* the {@link org.springframework.core.Ordered} interface.
* <p>The default implementation simply returns {@code Ordered.LOWEST_PRECEDENCE}.
* @param aspectClass the aspect class
*/
@Override
protected int getOrderForAspectClass(Class<?> aspectClass) {
Order order = AnnotationUtils.findAnnotation(aspectClass, Order.class);
if (order != null) {
return order.value();
}
return Ordered.LOWEST_PRECEDENCE;
return OrderUtils.getOrder(aspectClass, Ordered.LOWEST_PRECEDENCE);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,8 +18,7 @@ package org.springframework.aop.aspectj.annotation;
import org.springframework.aop.aspectj.SingletonAspectInstanceFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.core.annotation.OrderUtils;
/**
* Implementation of {@link MetadataAwareAspectInstanceFactory} that is backed
@@ -53,19 +52,9 @@ public class SingletonMetadataAwareAspectInstanceFactory extends SingletonAspect
return this.metadata;
}
/**
* Check whether the aspect class carries an
* {@link org.springframework.core.annotation.Order} annotation,
* falling back to {@code Ordered.LOWEST_PRECEDENCE}.
* @see org.springframework.core.annotation.Order
*/
@Override
protected int getOrderForAspectClass(Class<?> aspectClass) {
Order order = AnnotationUtils.findAnnotation(aspectClass, Order.class);
if (order != null) {
return order.value();
}
return Ordered.LOWEST_PRECEDENCE;
return OrderUtils.getOrder(aspectClass, Ordered.LOWEST_PRECEDENCE);
}
}