For projects heavily used of Java annotations, is there any suggestion on the annotation order? So as to uniform the code style in the team.
In almost all cases the answer is No, the order has no effect.
The @Order annotation defines the sorting order of an annotated component or bean. It has an optional value argument which determines the order of the component; the default value is Ordered. LOWEST_PRECEDENCE. This marks that the component has the lowest priority among all other ordered components.
The order of bean initialization is same as it's defined in the spring bean configuration file. The context is returned only when all the spring beans are initialized properly with post-init method executions. Employee name is printed as “Pankaj” because it was initialized in the post-init method.
@Primary indicates that a bean should be given preference when multiple candidates are qualified to autowire a single-valued dependency. There should be only one @Primary bean among same type of beans.
I'm going to say there's not. I could be proven wrong on this.
My reasoning is there are hundreds of projects that have annotations, in addition to the ones baked into Java, and the ones baked into our IDEs (specifically Eclipse but I'm sure others have them too.)
So, with all these libraries potentially competitng for "whose on top" I doubt they would agree on a standard.
I would encourage your team to sit down and make decisions about what's best for you guys.
Factors I would consider:
If you must impose an order, alphabetical?
Without some sort of knowledge about the annotations you are using, it's hard to suggest a rational ordering. Perhaps a better ordering would suit you and your team better; and if so, if you document what's the agreed order, the only thing left is to verify it follows the team agreed ordering.
After talking to your whole team, you might find you don't need to order them after all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With