如何解决groovy.lang.MissingMethodException:没有方法签名:methodMissing()适用于参数类型:()values:[]?
在我的项目中,我有两个插件,我在其中一个插件启动时遇到此异常(此插件的所有功能都很好)
我已经在这一行中获得了例外' findAllByStatus'
def newItemList = Item.findAllByStatus(ItemStatus.NEW)
我已在当前服务类中导入Item.groovy,并且在启动石英时启动时也会创建服务类。我不确定它是否与石英有关。
项目是域类。
class Item implements Serializable {
ItemStatus status
Date dateCreated
Date lastUpdated
def updateLastUpdated(){
lastUpdated = new Date()
}
static hasMany = [itemProperties : ItemProperty]
static mapping = {
table 'xcomms_item'
datasource 'xcomms'
}
static constraints = {
batch nullable:true
}
@Override
public int hashCode() {
return 13 * id.hashCode();
}
@Override
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Item) && (((Item)obj).id.equals(this.id))) {
return true;
}
return false;
}
}
堆栈跟踪:
groovy.lang.MissingMethodException: No signature of method: xcomms.Item.methodMissing() is applicable for argument types: () values: []
at xcomms.CommunicationBatchProcessService.communicationProcesss(CommunicationBatchProcessService.groovy:53)
at xcomms.AutomatedCommunicationJob.execute(AutomatedCommunicationJob.groovy:16)
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:59)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
2013-11-14 14:20:00,112 [QuartzJobCluster_Worker-2] ERROR quartz2.JobErrorLoggerListener - Exception thrown in job:xcomms.AutomatedCommunicationJob
org.quartz.JobExecutionException: xcomms.communication.exception.CommunicationProcessException: Error in processing communication batch [See nested exception: xcomms.communication.exception.CommunicationProcessException: Error in processing communication batch]
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Caused by: xcomms.communication.exception.CommunicationProcessException: Error in processing communication batch
at xcomms.AutomatedCommunicationJob.execute(AutomatedCommunicationJob.groovy:19)
at grails.plugin.quartz2.GrailsArtefactJob.execute(GrailsArtefactJob.java:59)
... 2 more
Caused by: groovy.lang.MissingMethodException: No signature of method: xcomms.Item.methodMissing() is applicable for argument types: () values: []
at xcomms.CommunicationBatchProcessService.communicationProcesss(CommunicationBatchProcessService.groovy:53)
at xcomms.AutomatedCommunicationJob.execute(AutomatedCommunicationJob.groovy:16)
... 3 more
ItemStatus是:
public enum ItemStatus {
NEW(0,"New"),BATCHED(1,"Batched"),SENT(2,"Sent")
final int id
final String name
private ItemStatus(int id, String name) { this.id = id; this.name = name;}
static ItemStatus getById(int i){
for( entry in ItemStatus.values() ){
if(entry.id == i)
return entry
}
}
}
答案 0 :(得分:2)
我为解决这个问题所做的是推迟Quartz Scheduler的开始。正如Ima所说,有一种竞争条件使GORM在Grails应用程序完全启动之前无法使用。如果您之前尝试使用它,则会得到MissingMethodException
。
我的解决方案涉及在完成所有初始化后禁用Quartz Scheduler autoStartup
(请参阅https://github.com/9ci/grails-quartz2/blob/07ecde5baa59e20f99c05302c61137617c08fc81/src/groovy/grails/plugin/quartz2/QuartzFactoryBean.groovy#L61)和start()
{/ 1}}。
这是阻止autoStartup的配置:
Bootstrap.groovy
使用这种方式,你不必像Ima建议的那样放弃使用GORM。
答案 1 :(得分:1)
最后,我找到了解决方案。
在启动时,quartz会加载服务类,但此时无法执行GORM命令。然后我将其更改为本机sql select * from xcomms_item where status = 0
。现在它工作正常。