messages.properties is the default resource bundle that stores user-facing text as key-value pairs so your application can show it in different languages. In Spring Boot, a file named messages.properties on the classpath is picked up automatically by the auto-configured MessageSource. Locale-specific files such as messages_de.properties or messages_fr.properties override the default for matching users. This is the standard way to implement internationalisation (i18n) in Java and Spring applications.
The file holds one message per line, in key=value form. Code and templates refer to the key, never to the literal text.
Placeholders such as {0} and {1} follow the java.text.MessageFormat syntax and are filled in at runtime. One caution: in MessageFormat, a single quote is an escape character, so write don''t (two quotes) when a message contains an apostrophe and takes arguments.
Translations live in sibling files named with a locale suffix:
For a request with locale de_AT, lookup tries messages_de_AT, then messages_de, then the fallback and finally the base messages.properties. If a key is missing in a specific file, the next less specific file supplies it. Always keep every key in the base file so nothing shows up as a raw key.
By default Spring MVC chooses the locale from the Accept-Language request header through AcceptHeaderLocaleResolver. To let users switch language with a link such as ?lang=de, register a session-based resolver and an interceptor:
Spring Boot registers a MessageSource bean when it finds a bundle named messages. These properties adjust it:
basename takes a comma-separated list. Use a slash or dot for packages, without the file extension.fallback-to-system-locale=false stops Spring from falling back to the server's own locale when no file matches, so users get the default file consistently.cache-duration controls reloading; leave it unset to cache forever in production.Spring Boot reads these files as UTF-8 by default. Older Java versions (before 9) read ResourceBundle properties files as ISO-8859-1 and needed \uXXXX escapes. Current Java reads them as UTF-8, and Spring's MessageSource uses the configured encoding.
In Java, inject MessageSource and pass the locale:
In Thymeleaf, use the #{...} syntax:
For validation messages, reference a key in curly braces on the constraint, for example @NotBlank(message = "{error.required}"). Boot only resolves those keys from messages.properties when you wire the validator to the MessageSource or use a ValidationMessages.properties file, which Bean Validation reads by itself.
Outside Spring, the same files work with java.util.ResourceBundle:
order.status.shipped, not the English sentence.No, but messages is the Spring Boot default. Use spring.messages.basename to choose another name or several.
At the root of the classpath, normally src/main/resources. Files in subfolders need the folder in the basename, for example i18n/messages.
The file encoding and the configured encoding disagree. Save the file as UTF-8 and keep spring.messages.encoding=UTF-8.
MessageSource.getMessage throws NoSuchMessageException unless you pass a default message. Thymeleaf renders the key as ??key_locale??.
messages.properties holds externalised, translatable text that Spring Boot's MessageSource serves by key and locale. Add messages_xx.properties files for each language, choose the locale per request or per user, and use placeholders and stable keys. The same approach works in plain Java with ResourceBundle.