The @Order
annotation is used to specify the order in which AOP advice is executed, it doesn't sort lists. To achieve sorting on your list have your BeanInterface
classes implement the Comparable interface and override the compareTo
method to specify how the objects should be sorted. Then you can sort the list using Collections.sort(list)
. Assuming BeanInterface
has a method called getSortOrder
that returns an Integer
object specifying the object's sort order, you could do something like this:
@Component
public class MyClass implements BeanInterface, Comparable<BeanInterface> {
public Integer getSortOrder() {
return sortOrder;
}
public int compareTo(BeanInterface other) {
return getSortOrder().compareTo(other.getSortOrder());
}
}
Then you can sort the list like this:
Collections.sort(list);