spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Refine message.properties detection

Open philwebb opened this issue 10 years ago • 5 comments

Currently ResourceBundleCondition causes a full scan of every jar file, if we change the pattern to messages.properties rather than messages-*.properties it won't. Should make things faster at the expense of needing that file (even if empty).

philwebb avatar Jan 12 '16 15:01 philwebb

Or we could look at dropping the condition all together.

philwebb avatar Jan 12 '16 15:01 philwebb

I could be missing something, but this change doesn't seem to be documented in the Spring Boot Reference Document. Is messages.properties really required when using messages_.properties files?

Also, does this change not break backward compatibility?

Here's my scenario: I've messages_en.properties and messages_fr.properties files in the classpath, but no messages.properties file. This works fine with Spring Boot v1.3.0.

When I upgrade to v1.3.2, because of the lack of messages.properties file, MessageSourceAutoConfiguration is not creating a MessageResource bean on startup so AbstractApplicationContext.initMessageSource() will create a DelegatingMessageSource with parentMessageSource=null and later on the application throws this exception:

org.springframework.context.NoSuchMessageException: No message found under code 'msg-1' for locale 'en'.
    at org.springframework.context.support.DelegatingMessageSource.getMessage(DelegatingMessageSource.java:69) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]

davidkiss avatar Feb 18 '16 20:02 davidkiss

@davidkiss The documentation was never particularly clear on this in the first place so there wasn't anything to change there. I did add a note on the release blog about the change.

I'm afraid that the change really needs to stay so that a full jar scan is not required for every application.

philwebb avatar Feb 22 '16 06:02 philwebb

@philwebb, recently I updated a project from 1.3.1 to 1.4.1, and it failed to translate errors because this change. So I refactored the name of the messages file from messages_es.properties to messages.properties and worked again, but we are going to add support to more languages to this API soon.

What is the proper why to add more languages to a Spring Boot application after this change?

mrsarm avatar Sep 22 '16 18:09 mrsarm

@mrsarm messages.properties is simply used as a fallback when you don't have a specific file for the requested locale. As such, it's recommend that you always have one and its contents should be in whatever language seems most appropriate for use as a fallback. You should then continue to have files such as messages_es.properties that contain locale-specific messages.

wilkinsona avatar Sep 22 '16 18:09 wilkinsona