Search code examples
javaspringinternationalizationtemplate-engineresourcebundle

messageSource doesn't replace all arguments in template


I have code:

messageSource.getMessage("some.key",new Object[]{30,31},Constants.LOCALE)

and key inside property file:

some.key=Csv header length ({0}) doesn't correspond the mapping file size {1} .

but result is strange:

Csv header length (30) doesn't correspond the mapping file size {1} .

Fisrt variable was successfully replaced but second - not.

Why does second argument was not resolved?


Solution

  • The problem is because you have a single quote in the message that you have not escaped.

    See https://www.mscharhag.com/java/resource-bundle-single-quote-escaping for an example of your problem.