From the course: Java EE: Bean Validation

Unlock the full course today

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

Global custom validation failure messages

Global custom validation failure messages

From the course: Java EE: Bean Validation

Start my 1-month free trial

Global custom validation failure messages

- Validation messages can be configured at the global level if that suits your use case. The messages are all located in one file that must be on the class path. This is where the API looks for property files that contain all of your custom messages. So in my project, all files located in the resource directory are on the class path, so this is where I'm going to put my validation messages. So let's navigate to the resources location. So I'm going to create a file called ValidationMessages.properties. It's just a plain text file, nothing special, but it should be named this way. So just right click, new, and do file, and then it's going to be called ValidationMessages.properties. Now here is where I will configure my custom messages. I do this by specifying a message key and associating a custom message. And it's simply displayed like this: a key and message, it's a simple key value pair. But how do I know what the key name is? Well, you need to dive into the constraint annotation…

Contents