Affects: 5.2.7

A ControllerAdviceBean is not sorted based on the @Bean order.

e.g.

@RestControllerAdvice
public class BaseExceptionHandler {

    // Methods
}

@RestControllerAdvice
public class CoreExceptionHandler {

    // Methods
}

@Configuration
public class ExceptionHandlerConfiguration {


    @Bean
    @Order(20)
    public BaseExceptionHandler baseExceptionHandler() {
        return new BaseExceptionHandler();
    }

    @Bean
    @Order(10)
    public CoreExceptionHandler coreExceptionHandler() {
        return new CoreExceptionHandler();
    }
}

The @Order on the bean definitions is ignored. When ControlerAdviceBean#findAnnotatedBeans(applicationContext) is returned then the list contains BaseExceptionHandler and then CoreExceptionHandler (although the order based on @Order should be the other way around).

When the exception handlers implement the Ordered interface everything is OK. Not sure if this is a bug or it works as designed like that.

I can't add @Order or implemented Ordered because we want our users to be able to override those beans and provide their own before or after our defined beans. They can also entirely replace them when using Spring Boot because we use ConditionalOnMissingBean#name.