读取docker容器配置信息



在docker容器中设置了一些参数。我想从我的spring引导应用程序中读取这些配置。我可以使用环境变量。

读取吗?

感谢

您可以简单地在application.properties文件中指定它,如下所示:

param.name=${PARAM_NAME_IN_CONTAINER}

之后,你可以像下面这样注入到你的应用程序中:

@Value("${param.name}"
String myContainerParam;

属性spring.profiles示例

方式1:使用自定义环境变量ENV_VAR_IN_CONTAINER

您需要添加到application.properties:

spring.profiles=${ENV_VAR_IN_CONTAINER}

方式2:使用spring友好的环境变量SPRING_PROFILES

Spring将自动使用此属性。

更多信息:https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config

最新更新