Looking for method argument validation framework based on AOP and annotations [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this questionI'm looking for argument validation framework which:
1) Allows specifying argument constraints via annontations (like OVal, JaValid) 2) Validation code automatically injected (during compilation or runtime) into methods (i.e. no explicit call to Validator object is required)Example of what i'm looking for:
public class Person {
private String name;
....
//Method which arguments should be validated
public void setName(@NotBlank String name){
//<---validating code should be injected here
this.name = name;
}
}
Example of code i'm trying to avoid
//Example of call to the validated method
...
Person person = new Person();
person.setName("John");
...
...
Validator validator = new Validator(...);//g开发者_如何转开发lue code
Person person = new Person();
person.setName("John");
validator.validate(person);//glue code
...
Thanks for answers!
I think you meant "automatically injected during compilation or runtime", right?
I had the same problem. My solution was Spring Validation and self-written AOP layer (about three classes).
My validation code looks like this:
@Validational( validators = {"com.mycompany.MyValidator"} )
public void myMethod( String paramToValidate )
精彩评论