使用Consul进行配置的Spring Boot应用程序可以编译为GraalVM原生吗?

问题描述 投票:0回答:1

我有一个 Spring Boot (v3.1.4) 应用程序,我想将其部署为 AOT 编译映像。 DB url 特定于部署应用程序的每个环境。它使用 application.properties 中的属性“spring.datasource.url”。该值通过 Consul 提供给应用程序。 application.properties 包含连接到 Consul 的配置:

spring.config.import=consul:
spring.cloud.consul.enabled = true
spring.cloud.consul.config.enabled = true
spring.cloud.consul.config.fail-fast = true
spring.cloud.consul.host = ${CONSUL_SERVER}
spring.cloud.consul.port = ${CONSUL_PORT}
spring.cloud.consul.config.prefixes = config/${APP_ENVIRONMENT}
spring.cloud.consul.config.defaultContext = ${spring.application.name}

CONSUL_SERVER、CONSUL_PORT 和 APP_ENVIRONMENT 被定义为运行已部署应用程序的主机上的环境变量。

我遇到的问题是,当应用程序在部署主机上运行时,数据库 URL 是从 Consul 返回到构建主机的值。

此页面上有一段https://github.com/spring-cloud/spring-cloud-release/wiki/AOT-transformations-and-native-image-support涵盖了 Spring Cloud Config。在本段中,有一句话似乎表明来自 Consul 的值将在构建时被烘焙。但下一句似乎表明Consul会在运行时被查询。两者似乎都是正确的,但为什么呢?

如果 Consul 的值在运行时不会覆盖构建时 Consul 的值,那还有什么意义。

我必须为每个环境构建一个独特的本机镜像吗?

spring-boot consul graalvm
1个回答
0
投票

我找到了答案。部署的主机上不需要环境变量“APP_ENVIRONMENT=”,而是需要环境变量“spring.cloud.consul.config.prefixes=config/”。

© www.soinside.com 2019 - 2024. All rights reserved.