使用 uberjar 进行部署时覆盖 Typesafe 配置中的多个配置值 [英] Overriding multiple config values in Typesafe config when using an uberjar to deploy

查看:30
本文介绍了使用 uberjar 进行部署时覆盖 Typesafe 配置中的多个配置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 并出现在类路径上,然后出现在其他类路径条目(例如您的 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 文件中的 include "application" 指令将另一个 conf 文件包含到您的文件中.

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 对象或加载如果未提供,则来自默认配置.

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.

这篇关于使用 uberjar 进行部署时覆盖 Typesafe 配置中的多个配置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆