Grails项目 - Servlet调用 - ClassNotFoundException:javax.servlet.AsyncContext

时间:2014-03-10 09:17:11

标签: java servlets grails intellij-idea

我正在使用

  • intellij idea ultimate 12..4
  • grails 2.2.0,
  • BuildConfig.groovy文件中的grails.servlet.version =“2.5”

并实现了简单的servlet post请求。使用RESTClient进行发布请求我找到了这些scenariol

情景:

  • 我在本地使用时效果很好。 URL:localhost:9090 / testProject / api / testReport

  • 但是当我在本地服务器中部署它时,会显示以下错误消息:URL:192.168.1.10:9090 / testProject / api / testReport

本地服务器配置与localhost一样....

code:   
ERROR errors.GrailsExceptionResolver  - ClassNotFoundException occurred when processing request: [POST] /testProject/api/testReport
        javax.servlet.AsyncContext. Stacktrace follows:
        java.lang.ClassNotFoundException: javax.servlet.AsyncContext
                at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
                at java.lang.Class.getDeclaredMethods(Class.java:1808)
                at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
                at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
                at org.grails.jaxrs.support.ConverterUtils.jsonToMap(ConverterUtils.groovy:94)
                at org.grails.jaxrs.support.DomainObjectReaderSupport.readFromJson(DomainObjectReaderSupport.groovy:124)
                at org.grails.jaxrs.support.DomainObjectReaderSupport.readFrom(DomainObjectReaderSupport.groovy:93)
                at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474)
                at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
                at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
                at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
                at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:183)
                at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
                at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
                at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
                at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
                at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
                at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
                at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
                at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
                at org.grails.jaxrs.web.JaxrsContext$JaxrsServiceImpl.process(JaxrsContext.java:192)
                at org.grails.jaxrs.JaxrsController$_closure1.doCall(JaxrsController.groovy:48)
                at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
                at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
                at org.grails.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:46)
                at java.lang.Thread.run(Thread.java:722)

2 个答案:

答案 0 :(得分:3)

经过几天的搜索和整合,我找到了解决方案......

  1. 为什么ClassNotFoundException异常最常发生在这里,文章真的很好......

    http://javarevisited.blogspot.com/2011/08/classnotfoundexception-in-java-example.html

  2. 问题的主要原因显示日志 java.lang.ClassNotFoundException:javax.servlet.AsyncContext

    这意味着它没有找到javax.servlet-3.0提供的asyncContext类。在servlet 2.5中它缺失了。

  3. 我在localhost中运行Apache Tomcat 7,但在本地服务器192.168.1.10中,我正在运行Apache Tomcat 6。在给定的链接中,apache doc说servlet版本。

     So the solution is either anyone upgrade the Apache Tomcat 6 to Apache Tomcat 7
     or posting the file javax.servlet-3.0 in Apache Tomcat 6 lib folder.
     [Here][3] is the jar file.
    

答案 1 :(得分:0)

您还可以强制Grails应用使用Servlet 2.5 在您的BuildConfig.groovy

grails.servlet.version =" 2.5"

希望有所帮助

爱德华