为什么 Spring Boot embedded tomcat 无法在 Google Compute Engine 上启动?

Why Spring Boot embedded tomcat can't start on Google Compute Engine?

我试图在 GCE 实例 运行 CentOS 7 上启动 spring 启动应用程序,但它似乎在完成 Web 应用程序初始化之后但在显示最终“服务器成功启动消息”之前挂起”。记录到控制台的最后一条消息是:

2016-03-18 07:34:04.802  INFO 1175 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet : 'dispatcherServlet' to [/]

我怀疑它与 GCE 问题跟踪器上报告的 this issue 有关。

同一应用程序在 Amazon EC2 实例 运行 Amazon AMI 上正常启动。

原来 tomcat 在创建 SecureRandom 实例时卡住了

 [ost-startStop-1] o.a.c.util.SessionIdGeneratorBase        : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [568,680] milliseconds.                                     

有关 Entropy Source

的 tomcat 文档中讨论了该问题

在启动 spring 引导应用程序时将 -Djava.security.egd=file:/dev/./urandom 添加到 jvm 参数修复了该问题。

为什么这发生在 CentOS 而不是亚马逊 linux? 引用自BEA Logic SIP Server documentation

The library used for random number generation in Sun's JVM relies on /dev/random by default for UNIX platforms.

.. on some operating systems /dev/random waits for a certain amount of "noise" to be generated on the host machine before returning a result.