2015-01-14 40 views
0

我在Tomcat7中部署了兩個相同Grails應用程序的實例。我用下面創建的戰爭,使用環境中的配置文件:Tomcat 7中第二個Grails應用程序中的IllegalStateException

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 [[email protected]] 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 [[email protected]] 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),它是不相關的... 如果我取消部署和重新部署相同的戰爭,而不清理數據庫,應用程序正常啓動。 這個stacktrace怎麼樣?

+0

有幫助的建議嗎? – FrancescoDS

回答

1

你的問題似乎在SecUserSecRole.groovy:32。我敢打賭,這是您的應用首次試圖訪問數據庫的位置。您可以發佈SecUserSecRole.groovy的相關部分以及您的數據庫配置的詳細信息嗎?

+0

我已經解決了檢查你建議的這一行。在生產中沒有堆棧跟蹤,所以我在開發中運行並解決了問題。謝謝! – FrancescoDS

+0

是啊,你是怎麼解決它的。這對其他遇到同樣問題的人會有幫助,例如我自己:) – pczeus

+0

解決方案是什麼? –

2

有在這一行的一個問題:Grails的-Dgrails.env = INSTANCE1戰爭

-Dgrails.env應設置環境名稱,如:開發,測試,督促或myCustomEnv,的不是名稱應用。

該設置告訴Grails根據提供的名稱查找DataSource.groovy和Config.groovy環境部分中的設置並應用它們。如果他們不存在,誰知道你最終會得到什麼。

正如您在堆棧跟蹤中看到的,當Grails嘗試執行環境塊時,您會收到空指針異常。這是因爲你給它的價值不存在。

+0

你說得對。我錯了......我應該寫nameOfEnv而不是nameOfApp! – FrancescoDS

相關問題