spring - Grails MongoDB 无法在 Tomcat 上运行应用程序

标签 spring mongodb tomcat grails

使用 Grails 2.3.8 和 MongoDB 插件 3.0.3。我的 MongoDB 数据库由 MongoLab 托管。当我在本地启动应用程序时,没有任何问题。

但是,当创建 WAR 文件然后将其托管在 Tomcat 服务器上时,会出现以下错误:

2015-08-25 18:50:19,604 [ContainerBackgroundProcessor[StandardEngine[PSA]]]
ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
    at java.lang.Thread.run(Thread.java:701)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2575)
    at java.lang.Class.getDeclaredMethods(Class.java:1857)
    at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
    at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
    at java.lang.Class.forName(Class.java:274)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.AsyncContext
    ... 6 more
2015-08-25 18:50:19,607 [ContainerBackgroundProcessor[StandardEngine[PSA]]]
ERROR context.GrailsContextLoader - Error initializing the application:
Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
    at java.lang.Thread.run(Thread.java:701)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2575)
    at java.lang.Class.getDeclaredMethods(Class.java:1857)
    at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
    at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
    at java.lang.Class.forName(Class.java:274)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.AsyncContext
    ... 6 more
2015-08-25 18:50:19,608 [ContainerBackgroundProcessor[StandardEngine[PSA]]]
ERROR context.GrailsContextLoader - Error initializing Grails:
Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
    at java.lang.Thread.run(Thread.java:701)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2575)
    at java.lang.Class.getDeclaredMethods(Class.java:1857)
    at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
    at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
    at java.lang.Class.forName(Class.java:274)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.AsyncContext
    ... 6 more Aug 25, 2015 6:50:19 PM
org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'grailsApplication' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
    at java.lang.Thread.run(Thread.java:701)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2575)
    at java.lang.Class.getDeclaredMethods(Class.java:1857)
    at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
    at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
    at java.lang.Class.forName(Class.java:274)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.AsyncContext
    ... 6 more
Aug 25, 2015 6:50:19 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Aug 25, 2015 6:50:19 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/Sacramento]
startup failed due to previous errors
Aug 25, 2015 6:50:19 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type [org.codehaus.groovy.runtime.GroovyCategorySupport.MyThreadLocal] (value [org.codehaus.groovy.runtime.GroovyCategorySupport$MyThreadLocal@6f8786da]) and a value of type [null] (value [null]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
Aug 25, 2015 6:50:19 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: A web application created a ThreadLocal with key of type [org.springframework.core.NamedThreadLocal] (value [Prototype beans currently in creation]) and a value of type [null] (value [null]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
Aug 25, 2015 6:50:36 PM org.apache.catalina.core.ApplicationContext log
INFO: Manager: list: Listing contexts for virtual host 'serialbetter.com'

这是我的构建配置:

    grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)
    grails.project.class.dir = "target/classes"
    grails.project.test.class.dir = "target/test-classes"
    grails.project.test.reports.dir = "target/test-reports"
    grails.project.work.dir = "target/work"
    grails.project.target.level = 1.6
    grails.project.source.level = 1.6
    //grails.project.war.file = "target/${appName}-${appVersion}.war"

    grails.project.fork = [
        // Configure settings for compilation JVM, note that if you
        // alter the Groovy version forked compilation is required.
        // Compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256,  daemon:true],

        // Configure settings for the test-app JVM, uses the daemon by default
        test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

        // Configure settings for the run-app JVM
        run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],

        // Configure settings for the run-war JVM
        war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],

        // Configure settings for the Console UI JVM
        console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
    ]

    grails.project.dependency.resolver = "maven" // or ivy
    grails.project.dependency.resolution = {

        // Inherit Grails' default dependencies
        inherits("global") {

        // Specify dependency exclusions here; for example, uncomment
        // this to disable ehcache:
        //
        //     excludes 'ehcache'
    }

    log "error" // Log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve
    legacyResolve false // Whether to do a secondary resolve on plugin installation,
                        // not advised and here for backwards compatibility

    repositories {
        inherits true // Whether to inherit repository definitions from plugins

        grailsPlugins()
        grailsHome()
        mavenLocal()
        grailsCentral()
        mavenCentral()

        // Uncomment these (or add new ones) to enable remote dependency
        // resolution from public Maven repositories
        //
        //mavenRepo "http://repository.codehaus.org"
        //mavenRepo "http://download.java.net/maven/2/"
        //mavenRepo "http://repository.jboss.com/maven2/"
    }

    dependencies {
        // Specify dependencies here under either 'build', 'compile', 'runtime',
        // 'test' or 'provided' scopes e.g.
        //
        // runtime 'mysql:mysql-connector-java:5.1.27'
        // runtime 'org.postgresql:postgresql:9.3-1100-jdbc41'
    }

    plugins {
        // Plugins for the build system only
        build ":tomcat:7.0.52.1"

        // Plugins for the compile step
        compile ":scaffolding:2.0.3"

        //Compile ':cache:1.1.2'
        compile ':mongodb:3.0.3'
        compile ":webxml:1.4.1"

        // Plugins needed at runtime but not for compilation
        //runtime ":hibernate:3.6.10.13" // or ":hibernate4:4.3.5.1"
        runtime ":database-migration:1.4.0"
        runtime ":jquery:1.11.0.2"
        runtime ":resources:1.2.7"
        //runtime ":simple-blog:0.3.3"

        // Uncomment these (or add new ones) to enable additional resources capabilities
        //
        //runtime ":zipped-resources:1.0.1"
        //runtime ":cached-resources:1.1"
        //runtime ":yui-minify-resources:0.1.5"

        // An alternative to the default resources plugin is the asset-pipeline plugin
        //compile ":asset-pipeline:1.6.1"

        // Uncomment these to enable additional asset-pipeline capabilities
        //compile ":sass-asset-pipeline:1.5.5"
        //compile ":less-asset-pipeline:1.5.3"
        //compile ":coffee-asset-pipeline:1.5.0"
        //compile ":handlebars-asset-pipeline:1.3.0.1"
    }
}

这是数据源:

environments {
    development {
        grails {
            mongo {
                host = "ds059682.mongolab.com"
                port = 59682
                username = "xxx"
                password="yyy"
                databaseName = "sacramento"
            }
        }
    }
    test {
        grails {
            mongo {
                host = "ds059682.mongolab.com"
                port = 59682
                username = "xxx"
                password="yyy"
                databaseName = "sacramento"
            }
        }
    }
    production {
        grails {
            mongo {
                // based on: cloudbees:123@paulo.mongohq.com:10044/456
                         host = "ds059682.mongolab.com"
                port = 59682
                username = "xxx"
                password="yyy"
                databaseName = "sacramento"
            }
        }
    }
}

我该如何解决这个问题?

最佳答案

您的应用程序似乎没有运行,因为您的 Tomcat 实例不包含 javax.servlet.AsyncContext 类,导致:

java.lang.ClassNotFoundException: javax.servlet.AsyncContext

该类在 Servlet 3.0 中引入,它是 Java EE 的一部分6. Servlet 2.5 是 Java EE 5 的一部分。您需要升级到 Tomcat 7这是一个 Servlet 3.0 容器。

  • Tomcat 7.X 包含 servelet 3.0
  • Tomcat 6.X 包含 servelet 2.5

关于spring - Grails MongoDB 无法在 Tomcat 上运行应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32210894/

相关文章:

java - 通过JAVA获取mongodb中的currentdate

java - 如何使用java使用mongodb中的文档来使用 "$or"运算符

php - 如何设置Backbone Model.idAttribute?

eclipse - 将 Grails 项目从 2.2.1 升级到 2.3.6;使用 Tomcat 运行应用程序失败,无法使用 Jetty 进行调试

java - 尝试在 jQuery + Struts2 中执行 ajax getJson 或 post 操作时,Tomcat7 出现 500 内部服务器错误

java - 是否可以在 spring batch 中跨单个文件进行分区?

spring - 什么时候检查证书链?相互认证

java - 无法识别java 8 lambda但配置没问题

java - 无法配置 Spring Batch 以因此运行作业

java - Java分布式计算,应用服务器的选择