Resolve message from property file
-
21-08-2019 - |
Question
How can we resolve a message from properties file? Just like when we use
errors.reject ( "xyz.abc" );
in this case "xyz.abc" is resolved from the property file specified in messageResource ( servlet.xml )
Solution
Implement the MessageSourceAware
interface in your class. Something like this should do the trick.
public class Foo implements MessageSourceAware {
protected MessageSource messageSource;
...
public void setMessageSource(MessageSource messageSource) {
this.messageSource = messageSource;
}
...
public String bar(HttpServletRequest request, ...) {
return messageSource.getMessage("xyz.abc",
new Object[] { "arg1", "arg2" },
RequestContextUtils.getLocale(request));
}
}
OTHER TIPS
Just implement org.springframework.context.MessageSourceAware
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow