I have resource bundle with one of the key/value pairs looking like:
my.key=A message specifying min: {min} and max: {max} parameters
It all works well when used with @Length annotation, Thymeleaf and validators. If error conditions are met the message gets resolved and displayed, however if I try to resolve the same message using the MessageSource.getMessage(...) method there's now way I can get this to work.
I tried the following;
messageSource.getMessage("my.key", new Object[] {Map.of("min", 4, "max", 16)}, validLocale);
also
messageSource.getMessage("my.key", new Object[]{"{min:4}", "max:16"}, validLocale);
And a few more things but every time I get IllegalArgumentException caused by NumberFormatException with the message: "can't parse argument number: min"
Will appreciate any suggestions
Your code should work, but you have to modify it slightly
And change your key to something like
MessageSource doesn't support named arguments (e.g. {min}).
minandmaxin @Length are just attributes -- they have nothing to with the message.properties' placeholders.