我正在尝试通过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$1.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$1 (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$1
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.
项目参数为:
- 玩2.8.8 Scala 2.13.5
- SBT 1.5.0
- Java 11
该项目基于IntelliJ最终模板。
Heroku Procfile是这样的:
web: target/universal/stage/bin/bionplaydatawarehouse -Dhttp.port=${PORT}
系统。属性文件看起来像这样覆盖默认的Java 8版本:
java.runtime.version=11
当我更改Java版本时,编译崩溃并产生类强制转换异常。
似乎Guice DI是问题所在,或者Heroku生产环境中缺少了一些配置参数,因为在本地项目运行良好。
我明白了!
需要添加-Dplay.http.secret.key参数,该值必须与您的应用程序秘密匹配。
不幸的是,这不是文档的一部分
web: target/universal/stage/bin/myProject - http. PORT =${PORT}-Dplay.http.secret.key = ' mySecret '