简体   繁体   English

如何解决groovy.lang.MissingMethodException?

[英]How to resolve groovy.lang.MissingMethodException?

How to resolve groovy.lang.MissingMethodException: No signature of method: methodMissing() is applicable for argument types: () values: []? 如何解决groovy.lang.MissingMethodException:没有方法签名:methodMissing()适用于参数类型:()values:[]?

In my project I have two plugins and I am getting this exception at start-up for one of the plugins (All the functionality of this plugin is fine) 在我的项目中,我有两个插件,我在其中一个插件启动时遇到此异常(此插件的所有功能都很好)

I've got the exception on this line for 'findAllByStatus' 'findAllByStatus'在这一行上有例外

def newItemList = Item.findAllByStatus(ItemStatus.NEW)

I have imported Item.groovy in current service class, also the service class is being created at start-up when quartz is starting. 我在当前服务类中导入了Item.groovy,并且在启动石英时启动时也会创建服务类。 I'm not sure if it is related to quartz or not. 我不确定它是否与石英有关。

Item is a domain class. Item是一个域类。

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;
    }

}

The stack trace: 堆栈跟踪:

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 is: 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
    }
}
}

What I've done to solve this problem is to postpone the start of the Quartz Scheduler. 我为解决这个问题所做的是推迟Quartz Scheduler的开始。 As Ima said, there is a kind of race condition that makes GORM not available until the Grails app has completely started. 正如Ima所说,有一种竞争条件使GORM在Grails应用程序完全启动之前无法使用。 If you try to use it before, you get a MissingMethodException . 如果您之前尝试使用它,则会出现MissingMethodException

My solution involved disabling the Quartz Scheduler autoStartup (see https://github.com/9ci/grails-quartz2/blob/07ecde5baa59e20f99c05302c61137617c08fc81/src/groovy/grails/plugin/quartz2/QuartzFactoryBean.groovy#L61 ) and to start() it in the Bootstrap.groovy after all the initialization was done. 我的解决方案涉及禁用Quartz Scheduler autoStartup (参见https://github.com/9ci/grails-quartz2/blob/07ecde5baa59e20f99c05302c61137617c08fc81/src/groovy/grails/plugin/quartz2/QuartzFactoryBean.groovy#L61 )并start()它完成所有初始化后,在Bootstrap.groovy

This is the config to prevent autoStartup: 这是阻止autoStartup的配置:

grails {
    plugin {
        quartz2 {
            autoStartup = false
        }
    }
}

Using this way you don't have to give up using GORM, as Ima suggested. 使用这种方式,你不必像Ima建议的那样放弃使用GORM。

Finally, I found the solution. 最后,我找到了解决方案。 At the start-up, quartz loads service class but it couldn't execute GORM commands at this point. 在启动时,quartz会加载服务类,但此时无法执行GORM命令。 Then I changed it to the native sql select * from xcomms_item where status = 0 . 然后我将其更改为本地sql select * from xcomms_item where status = 0 Now it works fine. 现在它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM