簡體   English   中英

ContextLoader - 在 ubuntu tomcat 上初始化 3 次根 WebApplicationContext

[英]ContextLoader - Root WebApplicationContext initialized 3 times on ubuntu tomcat

Dears, I have a jersey - spring api deployed on apache tomcat 9.0.46. (澤西處理寧靜的服務 JAX-RS 和 Spring 來處理我所有的 bean{控制器、DAO、SessionFactory、JPA 等......})。 Everything works fine on tomcat 9 on windows... When deploying the exact same war in ubuntu tomcat 9.0.46, the ContextLoader is getting triggered 3 times and I have all my singletons instantiated 3 times. 我正在 tomcat 端口 80 和 443 上部署 api(https - godady 證書)。 一旦我開始 tomcat,戰爭就被部署並且端口 80 和 443 開始(netstat -tulnp | grep java),我在日志中看到所有單例實例化。 (pool-2) Applicationcontext class 我的自定義 spring @Configuration class 並且它正在被觸發並且可以毫無問題地訪問數據庫

2021-06-09 14:41:52,128 1104 [main] INFO  o.s.web.context.ContextLoader - Root WebApplicationContext initialized in 905 ms
2021-06-09 14:41:53,124 2100 [pool-2-thread-1] INFO  skd.app.core.ApplicationContext - TASK::cleanExpiredStatuses

然后服務器需要幾分鍾(大約 10 分鍾 14:41 以上然后 14:51 以下),當端口 8005 啟動時,我再次看到 ContextLoader 再次觸發 2 次。

09-Jun-2021 14:51:36.196 WARNING [main] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [584,064] milliseconds.
09-Jun-2021 14:51:36.592 INFO [main] org.glassfish.jersey.server.ApplicationHandler.initialize Initiating Jersey application, version Jersey: 2.6 2014-02-18 21:52:53...
09-Jun-2021 14:51:37.042 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/apache-tomcat-9.0.46/webapps/skd-service.war] has finished in [588,185] ms

2021-06-09 14:51:39,388 696  [main] INFO  o.s.web.context.ContextLoader - Root WebApplicationContext initialized in 581 ms
09-Jun-2021 14:51:39.632 INFO [main] org.glassfish.jersey.server.ApplicationHandler.initialize Initiating Jersey application, version Jersey: 2.6 2014-02-18 21:52:53...
09-Jun-2021 14:51:40.013 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/opt/apache-tomcat-9.0.46/webapps/skd-service.war]

第三次:

2021-06-09 14:51:41,989 744  [main] INFO  o.s.web.context.ContextLoader - Root WebApplicationContext initialized in 605 ms
09-Jun-2021 14:51:42.232 INFO [main] org.glassfish.jersey.server.ApplicationHandler.initialize Initiating Jersey application, version Jersey: 2.6 2014-02-18 21:52:53...
09-Jun-2021 14:51:42.602 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/apache-tomcat-9.0.46/webapps/skd-service.war] has finished in [2,590] ms

在 windows 中一切正常,僅在部署到 ubuntu tomcat 時,我明白了。 有誰知道為什么 windows 和 ubuntu 之間的 tomcat 行為差異對於相同的 WAR 文件?

我已經設法找出問題所在。 該問題與 /conf/server.xml 中的 tomcat 配置有關。 多個主機將觸發每個主機觸發的上下文加載器。 我將所有主機的默認 appBase 保留為 webapps,從而為每個主機觸發了每個我的戰爭的 ContextLoader。 ContextLoader 也會多次觸發的另一個原因是在內部定義選項,除非您需要在戰爭之外加載一些東西。 我建議閱讀規格: https://tomcat.apache.org/tomcat-4.1-doc/config/host.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM