gpt4 book ai didi

java - Spring Boot——根据操作系统自动激活profile

转载 作者:行者123 更新时间:2023-12-04 00:52:15 26 4
gpt4 key购买 nike

假设我有一个特定于特定操作系统的 spring 配置文件:

spring:
profiles: mac
cloud:
zookeeper:
discovery:
preferIpAddress: false
instanceHost: docker.for.mac.localhost

有什么方法可以根据当前操作系统自动启用 spring 配置文件吗?

所以就我而言,我希望上述配置文件在 Darwin 操作系统上自动激活。

也许有一些方法可以用系统属性来做到这一点?在这种情况下,如果 os.name 包含“Darwin”,我希望 mac 配置文件处于 Activity 状态?

有什么想法吗?

最佳答案

这样的东西对你有用吗?当然你应该调整条件。

@SpringBootApplication
public class DemoApplication {

public static void main(String[] args) {
SpringApplication app = new SpringApplication(DemoApplication.class);
if (System.getProperty("os.name").contains("darwin")) {
app.setAdditionalProfiles("mac");
}
app.run(args);
}

}

关于java - Spring Boot——根据操作系统自动激活profile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65691169/

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