【发布时间】:2021-08-26 15:20:04
【问题描述】:
亲爱的, 我有一个 jersey - spring api 部署在 apache tomcat 9.0.46 上。 (Jersey 处理宁静的服务 JAX-RS 和 Spring 来处理我所有的 bean{控制器、DAO、SessionFactory、JPA 等...})。 在 Windows 上的 tomcat 9 上一切正常... 在 ubuntu tomcat 9.0.46 中部署完全相同的战争时,ContextLoader 被触发了 3 次,我将所有的单例实例化了 3 次。我在 tomcat 端口 80 和 443(https - godady 证书)上部署 api。 一旦我启动 tomcat,就会部署战争并启动端口 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 文件会有这种差异?
【问题讨论】:
-
显然你配置了 tomcat 为每个正在使用的连接器启动应用程序(每个端口使用一个连接器)。
-
我必须为 HTTPS 配置 443,为域的默认重定向配置端口 80 到 443,服务器在端口 8005 上运行。这是标准设置,在 windows 上完全相同,只是在ubuntu ContextLoader 被触发 3 次,一切都被独立实例化了 3 次。无论如何要控制这个?
标签: spring ubuntu tomcat jersey servletcontextlistener