- Notifications
You must be signed in to change notification settings - Fork 41.6k
Description
Spring Boot 3.4 M2.
It appears that when one defines their own messageSource
bean, it's not then possible to inject MessageSourceProperties
into the overriding bean for an alternative implementation to reuse certain bits of the configuration schema. That is, if I have my own:
@Bean public MessageSource messageSource(MessageSourceProperties properties) { // my own implementation... }
This will fail with:
[org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter] - <Application failed to start due to an exception> org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.autoconfigure.context.MessageSourceProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
I propose that alternative implementations of this bean should still be able to use MessageSourceProperties
.
This is of course because the MessageSourceAutoConfiguration
defines the following:
@ConditionalOnMissingBean( name = {"messageSource"}, search = SearchStrategy.CURRENT )
...and in the same class, MessageSourceProperties
is declared as a bean:
@Bean @ConfigurationProperties( prefix = "spring.messages" ) public MessageSourceProperties messageSourceProperties() { return new MessageSourceProperties(); }
So when a competing bean is found, this prevents MessageSourceProperties
to be created.
I find this somewhat unusual that MessageSourceProperties
is created explicitly as a Bean, and the class itself unlike many others is not tagged with @ConfigurationProperties(prefix ="spring.messages")
. I suspect that if this were the case, the problem would disappear. The binding would be recognized by the runtime and yet the bean implementation will be skipped in favor of the alternative but there may be a deeper rationale behind the change here.
Thank you for your time!