开发者

Looking for method argument validation framework based on AOP and annotations [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.

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 question

I'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 call to the validated method
...
    Person person = new Person();
    person.setName("John");
...
Example of code i'm trying to avoid
...
    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 )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜