Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Grails MongoDB无法在Tomcat上运行应用程序_Spring_Mongodb_Tomcat_Grails - Fatal编程技术网

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

Spring Grails MongoDB无法在Tomcat上运行应用程序,spring,mongodb,tomcat,grails,Spring,Mongodb,Tomcat,Grails,使用2.3.8和MongoDB插件3.0.3。我的MongoDB数据库由MongoLab托管。当我在本地启动应用程序时,没有任何问题 但是,当创建WAR文件并将其托管在服务器上时,会出现以下错误: 2015-08-25 18:50:19,604 [ContainerBackgroundProcessor[StandardEngine[PSA]]] ERROR context.ContextLoader - Context initialization failed org.springframe

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

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

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'
这是我的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"
    }
}
这是数据源:

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

该类是在Servlet3.0中引入的,Servlet3.0是Servlet6的一部分。Servlet2.5是JavaEE5的一部分。您需要升级到Servlet 3.0容器

Tomcat 7.X包含servelet 3.0 Tomcat6.X包含Servelet2.5 可能重复请尝试将grails.servlet.version=2.5更改为grails.servlet.version=3.0