【问题标题】:Grails java.lang.NoClassDefFoundError: org/springframework/mock/web/MockHttpServletRequestGrails java.lang.NoClassDefFoundError: org/springframework/mock/web/MockHttpServletRequest
【发布时间】:2017-04-28 07:43:59
【问题描述】:

在我的 Bootstrap groovy 中,我注册了一个简单的计时器作业以定期执行任务。然后,此计时器调用不同服务中的函数。函数代码如下:

 def syncForReminderSms() {
        try {

            def settings = GeneralSetting.findAll([cache: true])[0];
            Integer daysToSync = settings.reminderSmsScanTimeInDays;

            def results = PatientenTermin.withCriteria {
                def now = new Date()
                and {
                    eq('reminderSmsSent', false)
                    between('startzeit', now, now + daysToSync)
                }
            }

            smsTemplatesService.sendReminderSms(results);
        }catch(e) {
            println ("ERROR for SMS reminder trigger: " + e);
        }
    }

当计时器执行时,我收到标题中的错误。 try-catch 永远不会捕获任何东西。堆栈跟踪指出这一行:

and {

我真的被困在这里了。我尝试将运行时 'org.springframework:spring-test:3.1.0.RELEASE' 添加到运行时依赖项中,这是推荐的方法之一。但这没有帮助。

这里也是堆栈跟踪:

Exception in thread "Timer-0" java.lang.NoClassDefFoundError: org/springframework/mock/web/MockHttpServletRequest
        at grails.util.GrailsWebUtil.bindMockWebRequest(GrailsWebUtil.java:55)
        at grails.util.GrailsWebUtil$bindMockWebRequest.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
        at com.digithurst.global.domain.SchedulerService.syncForReminderSms(SchedulerService.groovy:42)
        at com.digithurst.global.domain.SchedulerService$$FastClassByCGLIB$$15b81381.invoke(<generated>)
        at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
        at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
        at com.digithurst.global.domain.SchedulerService$$EnhancerByCGLIB$$5900970a.syncForReminderSms(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
        at groovy.lang.MetaMethod$doMethodInvoke.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at groovy.lang.MetaMethod$doMethodInvoke.call(Unknown Source)
        at GrailsMelodyGrailsPlugin$_closure5_closure18_closure19.doCall(GrailsMelodyGrailsPlugin.groovy:175)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod.invoke(ClosureMetaMethod.java:80)
        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1068)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
        at BootStrap$_registerTimerJob_closure3.doCall(BootStrap.groovy:584)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:225)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
        at BootStrap$_registerTimerJob_closure3.doCall(BootStrap.groovy)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1058)
        at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1070)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)

【问题讨论】:

    标签: java spring spring-mvc grails groovy


    【解决方案1】:

    您错过了类路径中的spring-mock-&lt;version&gt;.jar。添加它,错误就会消失。

    如果您使用的是 maven,请将以下依赖项添加到您的 pom.xml:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-mock</artifactId>
        <version>2.0.8</version>
    </dependency>
    

    【讨论】:

    • 如何添加这个?
    • 嗯。感谢您的回答,但是我没有使用 Maven。我在 BuildConfig.groovy 中有我的依赖项
    • @Jacob 我不知道你的 groovy 文件,所以我无法帮助你
    • 最终你给我指出了解决方案。将 compile "org.grails.plugins:spring-mock:2.0" 添加到我的依赖项中就可以了.....
    猜你喜欢
    • 2016-11-10
    • 2020-04-16
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 2015-02-04
    • 2016-11-25
    • 2013-04-06
    • 2015-04-22
    相关资源
    最近更新 更多