Reputation: 37034
I use the @Min
annotation for field validation.
@Min(100)
private Long cost;
I want to extract the argument of the annotation in a separate configuration file.
Is there way to achieve it?
I understrand that I can write my own annotation and my own validator but I want to reuse a library's code.
Upvotes: 0
Views: 112
Reputation: 96
No way to do it with annotations like @Min, @Max and so on. You can use @AssertTrue to annotate a method of your entity in which your own validation logic will be implemented.
public class MyEntity {
private Long cost;
//getters and setters...
@AssertTrue
public boolean isValid() {
long minCost = MyExternalConfig.getMinCost(); //get data from where you want
return cost > minCost;
}
}
Upvotes: 2