我正在使用带有弹性搜索插件 0.18.7.1-SNAPSHOT 的 grails 2.0.0 M1。
我可以安装它,并且可以看到它使用默认配置运行良好。我还可以从我的 DBBootStrap.groovy 文件中看到我的域对象被创建并成功添加到索引中。
然而...
当尝试从 Web 层仅创建(不保存)域对象时(在 Bootstap 脚本成功运行后),我收到以下错误:
def testco = new Company(name:"test");
Line | Method
->> 13 | registerCustomEditors in org.grails.plugins.elasticsearch.conversion.CustomEditorRegistar
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 38 | test in com.tempism.company.CompanyController
| 886 | runTask . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 619 | run . . . . . . . . . in java.lang.Thread
进一步的调查揭示了一个堆栈跟踪,相关部分是......
java.lang.NullPointerException
at groovy.lang.MetaClassImpl.addToAllMethodsIfPublic(MetaClassImpl.java:2975)
at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:2954)
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:2918)
at groovy.lang.ExpandoMetaClass.initialize(ExpandoMetaClass.java:468)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:166)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:182)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:242)
at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:751)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:71)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
at org.grails.plugins.elasticsearch.conversion.CustomEditorRegistar.registerCustomEditors(CustomEditorRegistar.groovy:13)
at org.codehaus.groovy.grails.web.binding.GrailsDataBinder.registerCustomEditors(GrailsDataBinder.java:182)
at org.codehaus.groovy.grails.web.binding.GrailsDataBinder.registerCustomEditors(GrailsDataBinder.java:263)
at org.codehaus.groovy.grails.web.binding.GrailsDataBinder.createBinder(GrailsDataBinder.java:287)
at org.codehaus.groovy.grails.web.binding.DataBindingUtils.createDataBinder(DataBindingUtils.java:238)
at org.codehaus.groovy.grails.web.binding.DataBindingUtils.bindObjectToDomainInstance(DataBindingUtils.java:169)
at org.codehaus.groovy.grails.web.binding.DataBindingUtils.bindObjectToDomainInstance(DataBindingUtils.java:112)
at org.codehaus.groovy.grails.plugins.web.api.ControllersDomainBindingApi.initialize(ControllersDomainBindingApi.java:57)
at com.tempism.company.Company.<init>(Company.groovy)
在 grails 中相对较新,我不知道如何在 DBBootStrap 上下文中创建域对象/DataBinding,但不能在任何其他上下文(服务/控制器。
任何想法将不胜感激。
干杯。
更新...
//works
def co = new Company();
co.name = "hello"
co.save();
//doesn't work
new Company(name:"hello2").save();