Skip to content

Clarify documented behavior of MessageSource auto-configuration when no resource bundles matching the configured basenames exist #17485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
membersound opened this issue Jul 10, 2019 · 1 comment
Labels
type: documentation A documentation update
Milestone

Comments

@membersound
Copy link

membersound commented Jul 10, 2019

From spring-projects/spring-security#7067

If you set only one nonexisting message bundle, the following warning is printed correctly: spring.messages.basename=messages1

ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale en

If you set 2 nonexisting message bundles, the warning is missing:
spring.messages.basename=messages1, messages2

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 10, 2019
@wilkinsona
Copy link
Member

This is working as designed from a Spring Boot perspective. The warning is produced by a ResourceBundleMessageSource. Such a bean is auto-configured by MessageSourceAutoConfiguration if a resource bundle that matches one of the configured base names exists. You can see this in the auto-configuration report if you run your application with --debug. Here's the output with two base names for which there is no resource bundle:

   MessageSourceAutoConfiguration:
      Did not match:
         - ResourceBundle did not find bundle with basename messages,message-commons2 (MessageSourceAutoConfiguration.ResourceBundleCondition)

And here's the output when one exists:

   MessageSourceAutoConfiguration matched:
      - ResourceBundle found bundle URL [file:/Users/awilkinson/Downloads/resourcebundle-failure/target/classes/message-commons.properties] (MessageSourceAutoConfiguration.ResourceBundleCondition)
      - @ConditionalOnMissingBean (types: org.springframework.context.MessageSource; SearchStrategy: current) did not find any beans (OnBeanCondition)

This behaviour is what the documentation is attempting to describe when it says the following:

The auto-configuration applies when the default properties file for the configured resource bundle is available (i.e. messages.properties by default). If your resource bundle contains only language-specific properties files, you are required to add the default.

Let's see if we can word that differently to make the behaviour more clear.

@wilkinsona wilkinsona changed the title ResourceBundle not found - warning missing for 2 nonexisting message bundles Clarify documented behavior of MessageSource auto-configuration when no resource bundles matching the configured basenames exist Jul 11, 2019
@wilkinsona wilkinsona added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 11, 2019
@wilkinsona wilkinsona added this to the 2.1.x milestone Jul 11, 2019
@wilkinsona wilkinsona modified the milestones: 2.1.x, 2.1.7 Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

3 participants