Just found an odd issue when we were doing some refactoring.
We have had a resource bundle that did NOT include the default file (no locale postfix), and a second resource file that DID provide the default file. While both of these bundles were specified in basename everything worked. Messages from both files were found.
We removed the resource bundle that was 'correct' and had a default file, and now the first bundle with out the default, no longer worked. This is behavior is kind of expected, and there are lots of issues/docs around it. What I don't expect, is for the first scenario to work.
Working config:
spring.messages.basename=messages-core,other
Broken config:
spring.messages.basename=other
I would think, according to the docs and everything else I've read, both of these configs should be broken.
Attached a test project with a passing and failing test that exposes this behavior; demo.zip
Comment From: scottfrederick
Thanks for getting in touch. This situation is covered in the Spring Boot documentation:
The auto-configuration applies when the default properties file for the configured resource bundle is available (messages.properties by default). If your resource bundle contains only language-specific properties files, you are required to add the default. If no properties file is found that matches any of the configured base names, there will be no auto-configured MessageSource.
In your case, you are getting an empty MessageSource that has been created by Spring Framework, not one that has been configured by Spring Boot. If you set debug=true in your application.properties file you will see this in the conditions evaluation report:
Negative matches:
-----------------
...
MessageSourceAutoConfiguration:
Did not match:
- ResourceBundle did not find bundle with basename other (MessageSourceAutoConfiguration.ResourceBundleCondition)
Comment From: nstuart-idexx
@scottfrederick I am aware of that behavior (and have no problem with the fix), but this seems to be a bit of inconsistent behavior when the default properties file is not available for just some of the bundles. From that interpretation, we really only need 1 of the resource bundles specified to have a default properties file available, and any others are not needed, and that's that part that seems inconsistent to me.
I realize this is an edge case and "just do the right thing" is a fix here, but I feel like we could get a bit more warning or something about the first config and not having default files available for all Resource bundles specified.