4

Grails has amazing validation; is it possible to use it independent of the Grails framework?

We have a Java/Groovy Camel-based web application we can't convert to a Grails application. I'd love to use the Grails-style validation with the declarative constraints but have been unable to successfully configure the application to work with Grails libraries without converting the whole thing.

4

2 回答 2

4

Grails 提供的验证只是 Spring 的 bean 验证框架的包装。由于 Grails 是开源的,您可以看看它是如何完成的,并根据您自己的需要进行调整。开始寻找的最佳位置是GrailsDomainClassValidatorDomainClassGrailsPlugin以了解它是如何完成的。另一个有趣的地方是@Validateable AST 注释。

据我所知,并且从我在源代码中可以看到,没有独立的方法可以在 Grails 项目之外执行此操作,而无需编写自己的适应/实现。

于 2014-02-19T19:54:12.950 回答
-1

您可以毫无问题地使用外部验证。例如,可以在 Grails 项目的“lib”文件夹中使用外部“jar”(进行验证)文件。通过这种方式,就可以使用这个jar文件的API了。这是一种您可以使用的简单方法。

于 2014-02-19T19:56:03.867 回答