在使用uberjar部署时,在Typesafe config中覆盖多个配置值

在使用uberjar部署时,在Typesafe config中覆盖多个配置值

问题描述:

我有一个Akka应用程序,它使用 resource / application.conf 中定义的多个配置值(IP地址,端口号)。我使用 sbt-assembly 插件创建一个uber jar,然后部署这个jar。

I've an Akka application which uses multiple configuration values (IP address, port numbers) defined in resource/application.conf. I'm using the sbt-assembly plugin to create an uber jar and then deploying this jar.

有没有办法通过使用uber jar之外的另一个文件来覆盖整个 application.conf 文件? (即,使用新的conf文件中的值)

Is there a way to override the whole application.conf file by using another file that is outside the uber jar ? (i.e., values in the new conf file are used)

有多种方法可以实现:


  1. 您可以设置一个类路径,从外部目录中包含 application.conf ,并显示在classpath之前的其他类路径条目,如你的jar。为此,您可以使用常规的 java -classpath myconfdir:theapp.jar 并明确指定主类。

  1. You either set a classpath to include application.conf from external directory and appear on the classpath before other classpath entries like your jar. To do that you can use regular java -classpath myconfdir:theapp.jar and specify main class explicitly.

您可以将另一个conf文件包含在您的文件中,其中包含 includeapplication指令。

You can alternatively include another conf file into your file with include "application" directive in your conf file.

您可以在 application.conf 中设置环境变量,该变量将指向要包含的文件。你可以在shell中设置env。

You can set environment variable in application.conf that will point to a file to include. You set env in shell afterwards.

您可以以程序方式覆盖值: config.withValue(hostname,ConfigValueFactory.fromAnyRef( localhost) ActorSystem 接受Conf对象,如果没有提供,则从默认conf加载。

You can override values programmatically: config.withValue("hostname", ConfigValueFactory.fromAnyRef("localhost"). ActorSystem takes a Conf object or loads from default conf if not provided.

最简单的是仅使用 -Dconfig.resource = / dev.conf java命令行参数选择另一个文件

The easiest by far is to just pick another file with -Dconfig.resource=/dev.conf java command line argument.

有关详细信息,请参阅官方文档这里

For more details refer to official docs here.