Affects: 5.3.3


Trying to wrap the default MessageSource bean into my custom implementation using:

    @Bean
    @Primary
    public MessageSource wrapMessageSource( MessageSource messageSource ) {
        return new MyMessageSourceWrapper( messageSource );
    }

This has no effect because spring is hardwired to get bean with name MESSAGE_SOURCE_BEAN_NAME: https://github.com/spring-projects/spring-framework/blob/610de3ae786812f332b71a7453a67afd39834a03/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java#L771-L772

The @Primary bean should be used.

Comment From: snicoll

The @Primary bean should be used.

Thanks for the suggestion but the reference guide documents that this bean must be named messageSource. We need a bean name to avoid early initialization that can happen when a bean by type is requested.

Comment From: cdalexndr

So the workaround is to copy-paste code that initializes MESSAGE_SOURCE_BEAN_NAME to keep existing functionality and add my piece of code.... Not user friendly!