I want to add a bean to a list that is auto-wired into a 3rd-party library. The list already has two elements. I want my bean to be added to the end of the list, but instead it is added to the start.
I can annotate my bean with the Order annotation. To get it at the end of the list I should use:
@Bean
@Order(Ordered.LOWEST_PRECEDENCE)
public JacksonModuleRegistrar vendorExtensionsModule() {
return (objectMapper -> objectMapper.registerModule(new VendorExtensionsModule()));
}
However, the existing 3rd-party elements do not use the Order annotation, so by default they are also lowest precedence, and my bean still appears at the start of the list.
It seems to me that it would be better if the Spring default was zero instead of Integer.MAX_VALUE. Then I could annotate my element to go either before or after existing unannotated elements. Obviously, it's difficult for Spring to change that now and still be backwards compatible. Maybe they could introduce yet another annotation, similar to PriorityOrdered that does the opposite of that when encountered in OrderComparator.
Is there a way to make my bean appear after rather than before the existing elements in the auto-wired list?