標籤:stat ref driver 自動產生 ssl webapp classpath named loader
最近在用maven整合SSH做個人首頁時候,在eclipse裡面使用tomcat7外掛程式發布項目是沒有問題的,但當打包成war之後,使用tomcat7單獨發布項目,就出現了以下的錯誤.
嚴重: Context [/wangxin] startup failed due to previous errors八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc嚴重: The web application [/wangxin] 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.八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads嚴重: The web application [/wangxin] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads嚴重: The web application [/wangxin] 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.八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads嚴重: The web application [/wangxin] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1] but has failed to stop it. This is very likely to create a memory leak.八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads嚴重: The web application [/wangxin] appears to have started a thread named [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] but has failed to stop it. This is very likely to create a memory leak.八月 16, 2017 7:29:12 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads嚴重: The web application [/wangxin] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it. This is very likely to create a memory leak.
這個錯誤的意思是:在tomcat7啟動時候,tomcat內建的一個記憶體檢查的監聽器發現,你的項目使用了一個資料庫的串連池,並沒有關閉的情況下,又去註冊了一個串連池,為了保證記憶體不泄露,所以不允許你項目進行部署.
理論上,使用了SSH架構去整合了資料庫,使用了jpa和c3P0串連池,是根本不需要去關心是要去關閉串連和GC的,但是還是報錯,對此,就很有疑問了.
網上給出的理論是,因為tomcat7採用了一個監聽技術,所以就會這樣,完全可以關閉.但事實上,我關閉了之後,雖然啟動不報錯了,但是還是部署不了,日誌裡面還是這個錯誤.
同樣的,網上還說了一個方法,就是把資料庫的jar包放到tomcat的lib下面,我試了還是沒用.
最後層層排查,發現,錯誤出現在了我的applicationContext.xml上,為了方便開發,我把applicationContext.xml裡面的jdbc方面全部提取出來,放到了一個性的applicationContext-jdbc.xml檔案裡面,並且在總的xml裡面使用了<import>標籤去插入.
然後,我發現我的web.xml檔案配置有點不同,即spring的監聽器的classpath配置錯誤
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext*.xml</param-value></context-param>
我在classpath那邊配置多加了一個*這就導致了
正確的代碼:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value></context-param>
由於多配了一個*,這就導致了當啟動載入的時候,先載入了applicationContext-jdbc的內容,然後再載入applicationContext的內容,當載入appliactionContext的時候,再次去載入裡面<import>標籤匯入的applicationContext-jdbc內容,這就造成了一次項目載入了兩次資料庫的串連池,因此造成了重複載入,項目無法啟動的問題.
對於web.xml的配置,在這裡我還得說一個非常騷氣的問題.
不知先前什麼情況,在WEF-INF下自動產生了一個classes檔案夾,然後檔案夾裡面竟然多了一個applicationContext檔案(理論上編譯時間候,產生到target裡面的WEF-INF檔案夾下),這就造成了,當修改resource裡面的xml檔案時候,沒有修改到classes裡面的檔案,於是悲劇的一幕發生了:
使用SSH架構整合,使用SpringJPA整合的時候,寫了一個action,action裡面是使用的註解,注入的service,service裡面用註解注入的dao,dao唯寫了一個介面,介面繼承了JpaRepository.
使用junit直接調用service裡面方法,能擷取到資料庫裡面的資料,而使用tomcat啟動並執行話,調用action擷取不到資料.根本不報錯,使用debug發現,運行過程中,並沒有注入service以及dao.即都是null.
結果原因就是:在maven項目中的classes檔案夾下面,自動將resource全部複製過來,而在mavenresource裡面的設定檔是修改過的,這就導致了,junit和tomcat運行時候採用的applicationContext.xml檔案不同,導致了這個錯誤.而同時,在web.xml中,配置spring的監聽器使用的是
<param-value>classpath*:applicationContext.xml</param-value>
即載入所有classpath下面的xml檔案,這就造成了一種情況,就是在junit時候能載入spring自動注入,而使用tomcat卻載入不了,同時還不會報錯....
就這兩個關於web.xml的錯誤,與君共勉!
registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped.