Member-only story

@Order Annotation in Spring Boot

javatechonline blog
2 min readMay 17, 2021

What is @Order annotation in Spring Boot?

@Order annotation in Spring Boot represents the order of execution of a bean or an annotated component. The annotation @Order has an optional ‘value’ argument which takes an integer value. Based on this value the order of execution of components is decided. Moreover, we are allowed to pass either positive or negative value.

@Order Annotation In Spring Boot

How does @Order annotation work in Spring Boot?

However, the default value is Ordered.LOWEST_PRECEDENCE. This value represents that the component has the lowest priority among all other components. Likewise, the value Ordered.HIGHEST_PRECEDENCE represents that the component has the highest priority among components.

When user provides an integer value into it, the lower value will have the higher precedence. For example, a component having @Order annotation with value 1 will run before value 2.

If Component does not have @Order annotation, it will execute in alphabetical order of bean name by default. Furthermore, if two components are having the same order value, the execution will happen in the alphabetical order of component name.

In summary, below details of order will follow:
1) Components with order value of negative numbers
2)…

--

--

javatechonline blog
javatechonline blog

Written by javatechonline blog

Java, Spring Boot, Microservices Tutorials

Responses (2)