Spring Framework: 有关SpEL的“保留字”或“预定义变量”的列表吗?

huangapple go评论52阅读模式
英文:

Spring Framework: Is there a list of "reserved words" or "Predefined Variables" about SpEL?

问题

对于Spring Framework中关于SpEL的保留字或预定义变量的完整列表以及它们的相应解释在哪里?例如:

  • environment
  • systemProperties
  • systemEnvironment

例如,在这个有价值的教程中,只显示了上述列表中的最后两个:

请考虑如果Spring 6添加了更多的预定义变量,这将是一个改进,因此可能会有更多。

是的,我已经进行了研究 - 目前版本6 - 在官方文档中:

但其中不包含保留字。

注意:

是的,getSystemEnvironment()getSystemProperties() 方法出现在AbstractEnvironment类中,但请参阅以下类:

请查看“字段摘要”部分,其中包含systemEnvironmentsystemProperties变量,这些变量由SpEL使用。我假设其他类可能会有environment变量。

英文:

For Spring Framework where is the complete list of reserved words or Predefined Variables about SpEL with their respective explanation? It such as for:

  • environment
  • systemProperties
  • systemEnvironment

For example in this valuable tutorial is just shown the 2 latest of the list shown above

Consider if Spring 6 added more of them, it as an improvement, therefore could be more.

Yes, I did do a research - currently for version 6 - at the official documentation at:

But does not contain the reserved words.

Note:

Yes, appears the getSystemEnvironment() and getSystemProperties() methods at the AbstractEnvironment class, but see the following class:

See the Field Summary section, it has the systemEnvironment and systemProperties variables used by SpEL. I am assuming other class would have the enviroment variable

答案1

得分: 1

以下是已翻译的内容:

在SpEL中,实际上没有像您所寻找的保留词列表,至少在通用的SpEL解析和评估中没有。

默认情况下,Spring框架在应用程序上下文和@Value注解中提供了SpEL支持,如参考指南中所述:Bean定义中的表达式

这是通过SpEL的StandardEvaluationContext提供的,它使用beanFactory作为根对象。或者更确切地说,它使用bean工厂的BeanExpressionContext视图,同时为该评估上下文添加了一个专用的PropertyAccessor,以便在评估期间将bean工厂中的每个beanName视为根对象的属性。

因此,如果在工厂中注册了名为foo的bean,@Value("#{ foo }")将被解释为“根对象的属性foo”,它解析为上述的bean。

因此,systemPropertiessystemEnvironmentenvironment实际上并不是预定义的SpEL变量,而是AbstractApplicationContext中的标准bean。

英文:

There isn't really a list of reserved words for SpEL like what you are looking for, at least not in generic SpEL parsing and evaluation.

There is default SpEL support in the application context and notably in @Value annotations, as documented in the reference guide: Expressions in Bean Definitions.

Thi is provided via a SpEL StandardEvaluationContext which uses the beanFactory as the root object. Or rather, it uses a BeanExpressionContext view of the bean factory plus a dedicated PropertyAccessor is added to this evaluation context so that every beanName in the bean factory is considered a property of that root object during evaluation.

As a result, if a bean named foo is registered in the factory, @Value("#{ foo }") will be interpreted as "the property foo of the root object", which resolves to the aforementioned bean.

So systemProperties/systemEnvironment and environment are not really predefined SpEL variables, but rather standard beans in an AbstractApplicationContext.

huangapple
  • 本文由 发表于 2023年2月16日 02:44:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464184.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定