0

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!

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
Dexter
  • 1,621
  • 3
  • 18
  • 38
  • "I tried integrating it with my Spring project but it doesn't seem to work." - show us what you tried (i.e. code & config samples) and we may be able to help you. – Marcel Stör Dec 07 '14 at 21:10
  • @MarcelStör .. Valdr is a servlet application as mentioned here https://github.com/netceteragroup/valdr-bean-validation#servlet . The answer could be how to gracefully integrate the servlet application in a Spring web service application – Dexter Dec 17 '14 at 20:42
  • I know, I'm the developer of valdr Bean Validation. What exactly do you mean by "Spring web service application"? Your application does not run in a Servlet container? – Marcel Stör Dec 17 '14 at 22:29
  • I am using tomcat as a Servlet container. But I am unable to use valdr for my Spring project. But if I integrate valdr project as a servlet application, I was able to run it. Could you please, if possible, let me know if you have any examples of valdr project running under a Spring project? – Dexter Dec 17 '14 at 22:32
  • 1
    Sorry, still don't get it. If you've got a Servlet container there is a `web.xml` and if there is a `web.xml` you can configure the valdr Bean Validation Servlet, no? – Marcel Stör Dec 18 '14 at 11:40
  • We have our AngularJS App communicate with Spring REST services - we use the CLI during the maven build to generate the validation.json and it works just fine. – Manuel Manhart Nov 10 '15 at 14:38

1 Answers1

0

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.

user1464581
  • 377
  • 2
  • 10
  • 3
    I don't see how copying the answer from http://stackoverflow.com/q/12426758/131929 is gonna help in this case. If I'm not mistaken this question has absolutely nothing to do with with the one you copied the answer from. – Marcel Stör Dec 09 '14 at 14:09