java - Grails java.lang.NoClassDefFoundError : org/springframework/mock/web/MockHttpServletRequest

标签 java spring spring-mvc grails groovy

在我的 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)

最佳答案

您错过了spring-mock-<version>.jar在你的类路径中。添加它,错误就会消失。

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

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

关于java - Grails java.lang.NoClassDefFoundError : org/springframework/mock/web/MockHttpServletRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43674763/

相关文章:

java - 用Java计算面积;操作顺序

java - Java中的枚举。优点?

java - Eclipse Indigo、Glassfish 3.1.1 插件调试问题

java - Spring Cloud Stream RabbitMq - 从源代码设置属性

Spring webflow - 访问 session

java - key 哈希未得到验证以使用 facebook sdk 登录

java - 集群上 Spring session bean 中的静态变量

Java、Tomcat、ServletContextListener 和后台线程

java - Spring MVC session 属性初始设置

java - 我们可以在 Spring Webflux 中使用 web servlet 和 servlet 过滤器吗?