多個Context啟動衝突的問題解決
在Tomcat的server.xml中配置兩個context,出現其中一個不能正常啟動,交換配置順序,另一個又不能正常啟動,即始終只有第二個配置能啟動的情況。如果單獨部署,都沒有問題。報錯大致內容如下:
appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0] but has failed to stop it. This is very likely to create a memory leak.
起初以為是記憶體分配不夠,但加大了內容配置問題依然。
於是在localhost.log中又找到以下錯誤資訊:
嚴重: Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener
java.lang.IllegalStateException: Web app root system property already set to different value: 'webapp.root' = [/home/web/grows/] instead of [/home/web/mall/] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
大意是Log4jConfigListener在獲取webapp.root值時,被後一context的值替換掉了,所以要在各個專案的web.xml中配置不同的webAppRootKey值,隨即在其中一個web.xml中新增:
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>web.sample.root</param-value>
</context-param>
重啟tomcat,問題解決。