如何在 spel 中为 spring 个配置文件编写 AND 运算符

How to write AND operator in spel for spring profiles

我正在我的 Spring 应用程序中创建一个 bean。目前使用 Spring 3.2 太老了。我有一个 bean xml 文件,其中根 <beans> 标记具有 profile 属性。我希望在配置文件不是测试或 uat 时创建此文件中的 beans .. 所以像 profile="!test && !uat" 等。 我尝试了以下但 spring 不支持 && 运算符,所以我目前有 profile="!test, !uat"。从官方 Spring 文档中可以看出:

If a profile is prefixed with the NOT operator '!', e.g.

  <beans profile="p1,!p2">

indicates that the element should be parsed if profile "p1" is active or if profile "p2" is not active.

很明显,这在我的情况下不起作用,因为我只希望在配置文件不是测试和 uat 时创建 bean。有没有我不知道的可以使用的接线员?

选择包容方式,包含所有想要的配置文件(不包括排除的)

<beans profile="dev,prod,demo">

看看 SpEL docs:

像下面这样包裹表达式#{your_expression}

SpEL 支持运算符 &&, || 和关键字 and, or