ClassNotFoundException:grails.validation.ConstraintFactory

ClassNotFoundException: grails.validation.ConstraintFactory

我在独立模式下使用 GORM-mongodb:

compile 'org.grails:grails-datastore-gorm-mongodb:6.0.4.RELEASE'

我的域名 类 如:

@Entity
class Module {

  String id

  String tags

  Ability ability

  Map<String,String> metrics

  static constraints = {
    metrics nullable:true
  }

  static mapping = {
    version false
  }
}

我正在像这样初始化数据源:

new MongoDatastore( config, Ability, Module )

在 init-phaze 结束时,我总是看到错误:

ERROR org.grails.datastore.gorm.GormEnhancer - Unable to register GORM constraints: grails/validation/ConstraintFactory java.lang.NoClassDefFoundError: grails/validation/ConstraintFactory at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) at java.lang.Class.getDeclaredConstructors(Class.java:2020) at org.codehaus.groovy.reflection.CachedClass.run(CachedClass.java:77) at java.security.AccessController.doPrivileged(Native Method) at org.codehaus.groovy.reflection.CachedClass.initValue(CachedClass.java:74) at org.codehaus.groovy.reflection.CachedClass.initValue(CachedClass.java:72) at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:49) at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:36) at org.codehaus.groovy.reflection.CachedClass.getConstructors(CachedClass.java:271) at groovy.lang.MetaClassImpl.(MetaClassImpl.java:220) at groovy.lang.MetaClassImpl.(MetaClassImpl.java:230) at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createNormalMetaClass(MetaClassRegistry.java:171) at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createWithCustomLookup(MetaClassRegistry.java:161) at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.create(MetaClassRegistry.java:144) at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:253) at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:285) at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:258) at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:953) at org.codehaus.groovy.runtime.DefaultGroovyMethods.newInstance(DefaultGroovyMethods.java:15645) at org.grails.datastore.gorm.GormEnhancer.registerConstraints(GormEnhancer.groovy:394) at org.grails.datastore.gorm.GormEnhancer.(GormEnhancer.groovy:112) at org.grails.datastore.gorm.mongo.MongoGormEnhancer.(MongoGormEnhancer.groovy:38) at org.grails.datastore.mapping.mongo.MongoDatastore.(MongoDatastore.java:652) at org.grails.datastore.mapping.mongo.MongoDatastore.initialize(MongoDatastore.java:652) at org.grails.datastore.mapping.mongo.MongoDatastore.(MongoDatastore.java:228) at org.grails.datastore.mapping.mongo.MongoDatastore.(MongoDatastore.java:239) at org.grails.datastore.mapping.mongo.MongoDatastore.(MongoDatastore.java:330) at org.grails.datastore.mapping.mongo.MongoDatastore.(MongoDatastore.java:340) at org.grails.datastore.mapping.mongo.MongoDatastore.(MongoDatastore.java:382) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77) at org.codehaus.groovy.runtime.callsite.ConstructorSite.callConstructor(ConstructorSite.java:45) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235) at io.mozaiq.BootStrap.init(BootStrap.groovy:21) at io.mozaiq.BootStrap$init.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at io.mozaiq.ModuleStateVerticle.start(ModuleStateVerticle.groovy:30) at io.vertx.lang.groovy.GroovyVerticle.start(GroovyVerticle.groovy:64) at io.vertx.lang.groovy.GroovyVerticle.start(GroovyVerticle.groovy:93) at io.vertx.core.impl.DeploymentManager.lambda$doDeploy(DeploymentManager.java:434) at io.vertx.core.impl.ContextImpl.lambda$wrapTask(ContextImpl.java:316) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:440) at io.netty.util.concurrent.SingleThreadEventExecutor.run(SingleThreadEventExecutor.java:873) at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.ClassNotFoundException: grails.validation.ConstraintFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 54 common frames omitted

这是一个错误还是我做错了什么?

事实证明,必须添加另一个 grails 依赖项,例如

compile 'org.grails:grails-validation:3.1.14'

然后编译正常运行