java - 如何在 Spring 型材的 spel 中编写 AND 运算符

标签 java spring spring-profiles

我正在我的 Spring 应用程序中创建一个 bean。目前使用 Spring 3.2 已经相当老了。我有一个 bean xml 文件,其中根 <beans>标签有 profile属性。我希望当配置文件不是 test 或 uat 时创建此文件中的 bean ..所以类似 profile="!test && !uat" ETC。 我尝试了以下方法,但 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.

很明显,这在我的情况下不起作用,因为我只想在配置文件不是 test 和 uat 时创建 bean。是否有我不知道的可以使用的运算符?

最佳答案

看看 SpEL docs :

将表达式包裹起来,如下所示#{your_expression}

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

关于java - 如何在 Spring 型材的 spel 中编写 AND 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60599676/

相关文章:

java - 如何使 Spring 缓存中的缓存名称可配置?

java - 如果 session 过期,如何重定向到登录页面?

java - Cassandra:分区键只支持 EQ 和 IN 关系(除非你使用 token() 函数)

java - Spring框架中使用DataSourceInitializer初始化数据库时编码不正确

java - 在 Spring Boot 应用程序中修改 Activity 配置文件并刷新 ApplicationContext 运行时

java - 使用 Spring-Retry 指定特定于异常的退避策略

Eclipse WST : Webapp sometimes not deployed on Tomcat

java - 如何在不刷新页面的情况下将 Controller 变量值写回发送 Ajax 请求的 HTML 页面?

spring - 正确使用 Spring 环境配置文件以管理 PropertySourcesPlaceholderConfigurer 和属性文件集

spring - 如何以编程方式为任何环境设置事件配置文件?