出于测试目的,我正在尝试在内存中的 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/