没有什么特别的情况,并且我确定它刚刚开始发生了尝试grails clean
并没有摆脱这个问题:
域类:
static constraints = {
someThing(nullable:true, validator: this.checkSomething)
}
static def checkSomething= { val, obj, errors ->
if (val && obj.something?.findAll()?.size()>2 {
errors.rejectValue("something.error", [''] as Object[], '')
}
}
没有this.
以下错误。使用this.staticMethod ide抱怨它不是必需的。这是对的,我不应该需要它。只是想知道为什么这个奇怪的场景
错误导致:
Caused by: groovy.lang.MissingPropertyException: No such property: checkSomething for class: org.grails.orm.hibernate.cfg.HibernateMappingBuilder
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at com.example$__clinit__closure1.doCall(MyClass.groovy:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
at groovy.lang.Closure.call(Closure.java:426)
at com.example$__clinit__closure1.call(MyClass.groovy)
at groovy.lang.Closure.call(Closure.java:442)
at com.example$__clinit__closure1.call(MyClass.groovy)
at org.grails.orm.hibernate.cfg.HibernateMappingBuilder.evaluate(HibernateMappingBuilder.groovy:81)
at org.grails.orm.hibernate.cfg.HibernateMappingBuilder.evaluate(HibernateMappingBuilder.groovy)
at org.grails.datastore.mapping.config.AbstractGormMappingFactory.evaluateWithContext(AbstractGormMappingFactory.java:96)
at org.grails.datastore.mapping.config.AbstractGormMappingFactory.createMappedForm(AbstractGormMappingFactory.java:84)
at org.grails.orm.hibernate.cfg.HibernatePersistentEntity$1.<init>(HibernatePersistentEntity.java:41)
at org.grails.orm.hibernate.cfg.HibernatePersistentEntity.<init>(HibernatePersistentEntity.java:40)
at org.grails.orm.hibernate.cfg.HibernateMappingContext.createPersistentEntity(HibernateMappingContext.java:104)
at org.grails.datastore.mapping.model.AbstractMappingContext.addPersistentEntities(AbstractMappingContext.java:184)
at org.grails.orm.hibernate.cfg.HibernateMappingContext.<init>(HibernateMappingContext.java:55)
at org.grails.orm.hibernate.support.HibernateMappingContextFactoryBean.getObject(HibernateMappingContextFactoryBean.groovy:34)
at org.grails.orm.hibernate.support.HibernateMappingContextFactoryBean.getObject(HibernateMappingContextFactoryBean.groovy)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
... 63 common frames omitted
答案 0 :(得分:1)
我发现的解决方案涉及使用静态方法显式指定类的名称。我猜这个问题来自Grails用来支持静态约束= {thingsThatLookLikeParamsButAreReallyMethodCalls}语法的Groovy拦截器魔法。
class MyClassFoo {
static constraints = {
someThing(nullable:true, validator: MyClassFoo.checkSomething)
}
static checkSomething= { val, obj, errors ->
// your logic
}
}