问题描述
我正尝试通过Procfile使用环境变量配置我的Elastic beantalk Java应用程序,如下所示:
I'm attempting to configure my elastic beanstalk java application using environment variables via the Procfile like so:
web: ./bin/myservice -Dhttp.port=$PORT
PORT
环境变量是通过我的beantalk环境的软件配置"屏幕中的AWS ui设置的.
The PORT
environment variable is set via the AWS ui in the "Software Configuration" screen of my beanstalk environment.
但是,日志表明未插入$PORT
:
However, the logs are indicating that $PORT
is not being interpolated:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.whatever.services.myservice.Main.main(Main.scala)
Caused by: java.lang.NumberFormatException: For input string: "$PORT"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:569)
将选项传递到我的应用程序的正确方法是什么?
What is the correct way to pass options to my application?
这似乎是与sbt本机打包程序插件有关的问题,我使用它来创建项目的可分发zip存档.它生成的bin/myservice文件从字面上解释$ PORT并将其传递给应用程序.
Edit 1: This seems to be an issue related to the sbt native packager plugin which I use to create a distributable zip archive of the project. The bin/myservice file it generates is interpreting $PORT literally and passing that to the application.
推荐答案
尝试从Procfile
中删除-Dhttp.port=$PORT
.
在ui的软件配置"中,尝试将变量JAVA_OPTS
设置为-Dhttp.port=9000
(将9000替换为您的nginx代理使用的任何端口-我相信默认值为5000.)
In the ui in "Software Configuration" try setting the variable JAVA_OPTS
to -Dhttp.port=9000
(replace 9000 with whatever port your nginx proxy is using -- 5000 is the default I believe).
这篇关于环境变量在Elastic Beanstalk Procfile中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!