Valdr integration with Spring

255 Views Asked by At

I am interested in using valdr Bean Validation for my Spring 4 REST project, but it seems like valdr Bean Validation is only available with CLI and as Servlets.

I tried integrating it with my Spring project but it doesn't seem to work. I have been stuck on this for a while.

Could anyone please help me out with any examples of valdr Bean Validation integration with Spring?

Is there a specific configuration needed to integrate it?

Any help is appreciated!

Thank You!

1

There are 1 best solutions below

1
user1464581 On

Spring uses Gradle rather then Maven directly. Both are deployment/build libraries. Maven uses XML while Gradle uses Groovy. We can edit our build.gradle file to set it up.

First you must include the library, preferably from an artifactory similar to this:

dependencies {
    compile group: 'com.github.valdr', name: 'valdr-bean-validation', version: valdr_version
}

It should be possible to just include the library instead.

The example they showed in Maven could be written the following way in Groovy:

classes {
    doLast {
        buildValdrConstraints.execute()
    }
}

task buildValdrConstraints(type: JavaExec) {
    main = 'com.github.valdr.cli.ValdrBeanValidation'
    classpath = sourceSets.main.runtimeClasspath
    args '-cf', 'valdr_bean_validation.json'
}

The valdr_bean_validation.json file should contain config's such as the output directory which should be your server.

I'm not really a backend/Spring guy so I'm afraid i wont be the most help with questions.