gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:42:56 27 4
gpt4 key购买 nike

亲爱的,
我有一个 jersey - spring api 部署在 apache tomcat 9.0.46 上。 (Jersey 处理 Restful 服务 JAX-RS 和 Spring 来处理我所有的 bean{ Controller 、DAO、SessionFactory、JPA 等......})。
在 Windows 上的 tomcat 9 上一切正常...
在 ubuntu tomcat 9.0.46 中部署完全相同的 war 时,ContextLoader 被触发了 3 次,我将所有的单例实例化了 3 次。我在 tomcat 端口 80 和 443(https - godady 证书)上部署 api。
一旦我启动 tomcat,就会部署 war 并启动端口 80 和 443(netstat -tulnp | grep java),我在日志中看到所有单例实例化。 (pool-2)Applicationcontext 类我的自定义spring @Configuration 类,它被触发并且可以毫无问题地访问数据库

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,从而为每个主机触发了每个我的 war 的 ContextLoader。 ContextLoader 也会多次触发的另一个原因是在内部定义选项,除非您需要在 war 之外加载一些东西。
我建议阅读规范:
https://tomcat.apache.org/tomcat-4.1-doc/config/host.html

关于spring - ContextLoader - 根 WebApplicationContext 在 ubuntu Tomcat 上初始化 3 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67907215/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com