gpt4 book ai didi

java - 另一个属性键中使用的 Spring-boot 属性值

转载 作者:行者123 更新时间:2023-12-04 02:31:10 26 4
gpt4 key购买 nike

在我的 spring boot 项目中,我想在另一个属性键中使用一个属性值:

server.mode=mock

server.protocol.mock=http
server.host.mock=my.host-mock.org
...

server.protocol.prod=https
server.host.prod=my.host-prod.org
...
我想根据“server.mode”值使用相关的属性键 server.protocol.{value}
我怎么能这样做?
感谢帮助

最佳答案

您可以使用 spring 配置文件,您可以在其中为不同的部署环境设置不同的属性配置。
使用属性文件,您可以为每个配置文件创建一个属性文件,然后让 Spring Boot 根据 Activity 配置文件使用正确的属性配置。
project structureapplication-dev.properties

server.scheme=http
server.host=my.host-mock.org
application-prod.properties
server.scheme=http
server.host=my.host-mock.org
然后,您必须通过在 spring.profiles.active 中设置它来告诉 spring boot 要使用哪个配置文件。属性(property)。当使用应用程序 list (如 Cloud Foundry 或 Kubernetes)部署到云时,通过环境变量设置它很方便 SPRING_PROFILES_ACTIVE .
看官方 spring-boot documentation有关配置文件的更多信息。

关于java - 另一个属性键中使用的 Spring-boot 属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64142145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com