【问题标题】:IllegalStateException in second instance of Grails app in Tomcat 7Tomcat 7 中 Grails 应用程序的第二个实例中的 IllegalStateException
【发布时间】:2015-01-19 06:35:43
【问题描述】:

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

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中,但它不起作用...... 我要疯了,因为似乎应用名称有影响......

我已使用以下内容部署了应用程序:

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.access$301(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)是不相关的...... 如果我在不清理数据库的情况下取消部署并重新部署相同的战争,应用程序将正确启动。 这个堆栈跟踪呢?

【问题讨论】:

  • 有什么有用的建议吗?

标签: java tomcat exception grails


【解决方案1】:

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

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

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

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

【讨论】:

  • 你是对的。我错了...我应该写 nameOfEnv 而不是 nameOfApp!
【解决方案2】:

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

【讨论】:

  • 我已经解决了检查您建议的行的问题。在生产中没有堆栈跟踪,所以我在开发中运行并且我已经解决了这个问题。谢谢!
  • 是的,你是怎么解决的。这对其他可能遇到同样问题的人会有所帮助,比如我自己:)
  • 解决方案是什么?
猜你喜欢
  • 2014-04-12
  • 1970-01-01
  • 2011-05-26
  • 1970-01-01
  • 2011-01-11
  • 1970-01-01
  • 2012-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多