播放 2.8.8 在启动服务器时在 Heroku 上部署崩溃

Play 2.8.8 Deployment on Heroku crashes while starting the server

我正在尝试通过 Heroku CLI 在 Heroku 上部署一个 Scala Play 项目。

运行良好,但当服务器尝试启动时崩溃并出现以下错误:

2021-08-17T16:47:52.333689+00:00 app[web.1]: at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91)
2021-08-17T16:47:52.333713+00:00 app[web.1]: at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:306)
2021-08-17T16:47:52.333753+00:00 app[web.1]: at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
2021-08-17T16:47:52.333762+00:00 app[web.1]: at com.google.inject.internal.SingletonScope.get(SingletonScope.java:168)
2021-08-17T16:47:52.333789+00:00 app[web.1]: at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:39)
2021-08-17T16:47:52.333813+00:00 app[web.1]: at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:62)
2021-08-17T16:47:52.333838+00:00 app[web.1]: at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:213)
2021-08-17T16:47:52.333867+00:00 app[web.1]: at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184)
2021-08-17T16:47:52.333893+00:00 app[web.1]: at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:111)
2021-08-17T16:47:52.333919+00:00 app[web.1]: at com.google.inject.Guice.createInjector(Guice.java:87)
2021-08-17T16:47:52.333942+00:00 app[web.1]: at com.google.inject.Guice.createInjector(Guice.java:78)
2021-08-17T16:47:52.333968+00:00 app[web.1]: at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:200)
2021-08-17T16:47:52.333993+00:00 app[web.1]: at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:155)
2021-08-17T16:47:52.334018+00:00 app[web.1]: at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
2021-08-17T16:47:52.334042+00:00 app[web.1]: at play.core.server.ProdServerStart$.start(ProdServerStart.scala:53)
2021-08-17T16:47:52.334076+00:00 app[web.1]: at play.core.server.ProdServerStart$.main(ProdServerStart.scala:29)
2021-08-17T16:47:52.334102+00:00 app[web.1]: at play.core.server.ProdServerStart.main(ProdServerStart.scala)
2021-08-17T16:47:52.408221+00:00 heroku[web.1]: Process exited with status 255
2021-08-17T16:47:52.471552+00:00 heroku[web.1]: State changed from starting to crashed
2021-08-17T16:47:52.490499+00:00 heroku[web.1]: State changed from crashed to starting
2021-08-17T16:47:58.797308+00:00 heroku[web.1]: Starting process with command `target/universal/stage/bin/bionplaydatawarehouse -Dhttp.port=${PORT}`
2021-08-17T16:48:01.183756+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-08-17T16:48:01.398386+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-08-17T16:48:06.203049+00:00 app[web.1]: WARNING: An illegal reflective access operation has occurred
2021-08-17T16:48:06.203069+00:00 app[web.1]: WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils (file:/app/target/universal/stage/lib/com.google.inject.guice-4.2.3.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
2021-08-17T16:48:06.203069+00:00 app[web.1]: WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils
2021-08-17T16:48:06.203070+00:00 app[web.1]: WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
2021-08-17T16:48:06.203076+00:00 app[web.1]: WARNING: All illegal access operations will be denied in a future release
2021-08-17T16:48:15.071607+00:00 app[web.1]: Oops, cannot start the server.

项目参数为:

该项目基于 IntelliJ Ultimate 模板。

Heroku Procfile 如下所示:

web: target/universal/stage/bin/bionplaydatawarehouse -Dhttp.port=${PORT}

system.properties 文件看起来像这样覆盖默认 Java 8 版本:

java.runtime.version=11

当我更改 Java 版本时,编译崩溃并出现 Class Cast Exception。

似乎是 Guice DI 有问题,或者 Heroku 生产环境缺少某些配置参数,因为本地项目运行良好。

我明白了!

您需要添加 -Dplay.http.secret.key 参数,该参数的值必须与您的应用密码匹配。

很遗憾,这不是文档的一部分

web: target/universal/stage/bin/myProject -Dhttp.port=${PORT} -Dplay.http.secret.key='mySecret'