Custom Annotated Validation with Spring 3 Web MVC

My previous tutorial detailed using Hibernate Validation within Spring 3 Web MVC.  This tutorial shows how to create custom validation annotations.


This example annotation only permits the word ‘John’. Optionally, it can be case-sensitive. 

Creating the Annotation –

Within the above code JohnValidator.class  is specified as the validator.

Creating the Validator –


Now annotate the bean:


The form will look like this:


And a matching controller:


And that’s that.

For more on how to set this up as a project please see this previous tutorial. Details of the entire setup process including dependency libraries is detailed in the tutorial.




  • Bharath Kumar


    It gives an error as the object John is not initialized anywhere.
    Any idea how to resolve this.

    Constraint factory returned null when trying to create instance of JohnValidator