Reputation: 3278
Normally, we would validate a model with some constraint like so:
public class PersonForm {
@NotNull
@Size(min=2, max=30)
private String name;
@NotNull
@Min(18)
private Integer age;
}
However, I would like to use configurable properties instead of constants in my implementation. For instance, let this the properties
file:
personform.name.size.min=2
personform.name.size.max=30
and the form class...
public class PersonForm {
@NotNull
@Size(min="personform.name.size.min", max="personform.name.size.max")
private String name;
...
}
Is this possible with a declarative, annotation-based approach? Thank you.
Upvotes: 2
Views: 1050
Reputation: 40038
Try using Spring Expression language in annotation
@Size(min="${personform.name.size.min}", max="${personform.name.size.max}")
private String name;
Upvotes: 2