Annotations and validation properties file

I have a field in my spring bean (managed bean with jsf) and I check its length using the @Size annotation using the JSR303 bean check as follows:

@Size(min = 7, max = 15, message = "{password.range}")
private String newPassword;

and I was wondering how to read the min and max values ​​from the properties file, please report.

+5
source share
1 answer

New answer

This is not possible with its standard JSR 303 Validatators. The problem is that annotation values ​​are compile-time values, but values ​​in properties are only available at run time.

Of course, you can write your own JSR-303 Validators that read the value from the properties file during validation.

So you can use it like this:

@MySize (minKey = "password.min", maxKey = "password.max", message = "{password.range}" )

MySizeValidator minKey , .

+5