简体   繁体   中英

Grails MongoDB unable to run the application on Tomcat

Using Grails 2.3.8 and MongoDB plugin 3.0.3. My MongoDB database is hosted by MongoLab. When I start the application on local, there are no troubles.

But, when creating the WAR file and then hosting it on a Tomcat server, it gives me the following error:

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'

This is my BuildConfig:

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

This is the DataSource:

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

How can I fix this problem?

It seems like your application is not running, because your Tomcat instance doesn't contain class javax.servlet.AsyncContext , leading to:

java.lang.ClassNotFoundException: javax.servlet.AsyncContext

That class is introduced in Servlet 3.0 which is part of Java EE 6. Servlet 2.5 is part of Java EE 5. You need to upgrade to Tomcat 7 which is a Servlet 3.0 container.

  • Tomcat 7.X contains servelet 3.0
  • Tomcat 6.X contains servelet 2.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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