gpt4 book ai didi

java - 如果条件基于 Activeprofile

转载 作者:行者123 更新时间:2023-11-30 07:41:56 25 4
gpt4 key购买 nike

出于测试目的,我正尝试在内存中的 H2 中运行查询。由于 H2 限制,某些语法不起作用。我希望根据 Spring Boot 中的 @Activeprofile 更改语法。我的代码看起来像这样:

if (@Activeprofile("Test")) {
query = "something for test"
} else {
query = "something for prod/stage"
}

这可能吗?任何帮助表示赞赏。

最佳答案

您必须将 Environment Bean 注入(inject)到您的代码中。

像这样:

@Autowired
private Environment environment;

然后您可以使用 .getActiveProfiles() 方法。

if (Arrays.asList(environment.getActiveProfiles()).contains("...") {
...
}

有关此的更多信息,请参见 here.

关于java - 如果条件基于 Activeprofile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55376620/

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