Tomcat 7 中 Grails 应用程序的第二个实例中的 IllegalStateException

IllegalStateException in second instance of Grails app in Tomcat 7

我在 Tomcat7 中部署了同一个 Grails 应用程序的两个实例。我使用以下内容创建 wars,使用配置文件中的环境:

grails -Dgrails.env=instance1 war
grails -Dgrails.env=instance2 war

我使用 setenv.sh 进行 JAVA_OPTS 的额外配置和设置。

第一个实例运行正确。第二个给我以下错误:

Error 500: Internal Server Error

URI
    /instance2/
Class
    java.lang.IllegalStateException
Message
    No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

Trace

    Line | Method
->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread

有什么建议吗?

编辑:

我尝试用不同的名称部署第三个实例。它工作正常。所以我已经取消部署并将其重新部署到 Tomcat,但它不起作用... 我快疯了,因为好像app名字有影响...

我已经使用以下方法部署了应用程序:

grails -Dgrails.env=nameofapp war

其中 nameofapp 是应用程序的名称

我使用的是 Grails 2.2.1 版本

编辑 2:

我了解到该问题出现在首次部署应用时。事实上,当第一次部署到 Tomcat 时,我在 catalina.out 中看到以下内容:

java.lang.NullPointerException
at medicalofficemanager.SecUserSecRole.create(SecUserSecRole.groovy:32)
at BootStrap$_closure1.doCall(BootStrap.groovy:61)
at         grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:308)
at grails.util.Environment.executeForEnvironment(Environment.java:301)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:277)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
    Jan 18, 2015 5:49:49 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jan 18, 2015 5:49:49 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/MyAppName] startup failed due to previous errors
Jan 18, 2015 5:49:49 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/MyAppName] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Jan 18, 2015 5:49:49 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyAppName] appears to have started a thread named [net.sf.ehcache.CacheManager@d5381] but has failed to stop it. This is very likely to create a memory leak.
Jan 18, 2015 5:49:49 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyAppName] appears to have started a thread named [myapp.SecRole.data] but has failed to stop it. This is very likely to create a memory leak.
Jan 18, 2015 5:49:49 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyAppName] appears to have started a thread named [org.hibernate.cache.UpdateTimestampsCache.data] but has failed to stop it. This is very likely to create a memory leak.
Jan 18, 2015 5:49:49 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyAppName] appears to have started a thread named [org.hibernate.cache.StandardQueryCache.data] but has failed to stop it. This is very likely to create a memory leak.
Jan 18, 2015 5:49:49 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyAppName] appears to have started a thread named [net.sf.ehcache.CacheManager@13e45] but has failed to stop it. This is very likely to create a memory leak.
Jan 18, 2015 5:49:49 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/MyAppName] appears to have started a thread named [aclCache.data] but has failed to stop it. This is very likely to create a memory leak.
Jan 18, 2015 5:51:13 PM org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already.  Could not load net.sf.ehcache.store.compound.CompoundStore$KeySet.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1587)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
    at net.sf.ehcache.store.compound.CompoundStore.keySet(CompoundStore.java:216)
    at net.sf.ehcache.store.compound.factories.DiskStorageFactory$DiskExpiryTask.run(DiskStorageFactory.java:670)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

我认为第一个异常(关于 SecUserSecRole)是不相关的... 如果我在不清理数据库的情况下取消部署并重新部署相同的 war,应用程序将正确启动。 这个堆栈跟踪怎么样?

您的问题似乎在 SecUserSecRole.groovy:32。我愿意打赌那是您的应用程序首次尝试进行数据库访问的地方。您能否 post SecUserSecRole.groovy 的相关部分以及您的数据库配置的详细信息?

这一行有问题:grails -Dgrails.env=instance1 war

-Dgrails.env 应设置为环境名称,例如:dev、test、prod 或 myCustomEnv,而不是应用程序的名称。

此设置告诉 Grails 在 DataSource.groovy 和 Config.groovy 的环境部分中根据提供的名称查找设置并应用它们。如果它们不存在谁知道你最终会得到什么。

正如您在堆栈跟踪中看到的那样,当 Grails 尝试执行环境块时,您遇到了一个空指针异常。这是因为你给它的值不存在。