From the course: Spring: Spring MVC

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Localizing error messages

Localizing error messages

From the course: Spring: Spring MVC

Start my 1-month free trial

Localizing error messages

- [Instructor] The last bit of the JSR Validations Demo is localizing error messages for validations from the .properties file. If you look in our user java bean, we have specified all the messages right there. Instead of that, you could move these messages to a .properties file, so that if you want to reuse them for any other purpose, you can do so. Now for that, what you have to do is simply add a file under the resources folder, and the name of the file should be validationmessages.properties. And under this validationmessages.properties, you can define the keys and the messages. And that will be in the form of key and value pair. So let's go back to the user bean, and let's say we want to make sure that this message is localized, so let's copy this, and go to the properties file, and let's define a key for that message, let's say we call it username.not.empty, and that will be equal to the actual message. And then…

Contents